node.js - 并行或同时构建 dotnet 核心

标签 node.js powershell .net-core dotnet-cli

this解决方案 我有 2 个应用程序:AppAAppB 共享类库 Shared。我已经尝试与 PowerShell 并行地自动构建/运行这些和 node脚本(我愿意接受其他解决方案)。我同时使用 --no-dependencies--no-restore 标志,但我间歇性地得到:

'CSC : error CS2012: Cannot open \'C:\\Users\\User\\source\\repos\\ParallelBuild\\Shared\\obj\\Debug\\netcoreapp2.0\\Shared.dll\' for writing -- \'The process cannot access the file \'C:\\Users\\User\\source\\repos\\ParallelBuild\\Shared\\obj\\Debug\\netcoreapp2.0\\Shared.dll\' because it is being used by another process.\' [C:\\Users\\User\\source\\repos\\ParallelBuild\\Shared\\Shared.csproj]\r\n'

电力外壳: ./build.ps1 enter image description here

Node : 运行项目 build-scriptnode ./build-script/app.js enter image description here

为什么 Shared 项目甚至使用 --no-dependencies 标志构建?如何并行或同时构建?

最佳答案

错误 CS2012 的解释:进程无法访问文件

我可以重现您的问题和 Process Monitor表示两个进程同时打开shared.dll进行读取。这会导致您描述的问题。

尽管可以通过使用 FileShare.Read 作为 documentation 从不同的进程读取相同的文件。表明(请参阅下面的摘录),这似乎不是csc.exe 完成。这是csc.exe的一个缺点,短期内可能不会改变。

Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file.

解决方案

除了使用 Start-Process 来实现并行构建,您还可以使用 msbuild,它开箱即用地支持这一点。

msbuild 支持并行构建,带有 /maxcpucount-switch 和 BuildInParallel-task 参数,如 MS build documentation 中所述.

通过在命令行上使用 /maxcpucount-switch 启用并行构建:

dotnet msbuild .\ParallelBuildAB.csproj /target:build /restore:false /maxcpucount:2

此外,还需要在项目文件 ParallelBuildAB.csproj 中使用 BuildInParallel-task 参数。请注意,引用了 AppA.csprojAppB.csproj:

<?xml version="1.0"?>
<Project name="system" default="build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="build">
        <MSBuild BuildInParallel="true" Projects="./AppA/AppA.csproj;./AppB/AppB.csproj" Targets="Build"/>
    </Target>
</Project>

关于node.js - 并行或同时构建 dotnet 核心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47895162/

相关文章:

c - 在终端上键入`node`时运行的代码

node.js - Nginx:[警告] 0.0.0.0:80 上的冲突服务器名称 "non.com",已忽略

c# - 我的 .net core 发布的可执行文件提供了与运行代码时不同的目录路径

asp.net-core - 如何在 blazor 服务器端关闭页面时获取事件?

javascript - Node JS 应用程序卡在resolve() 处

node.js - 如何用 `POST` 执行 `Node.js` ?

powershell - 在Windows PowerShell中设置环境变量

powershell - 无法在 Sitecore 项目上设置工作流程和工作流程状态属性

winforms - 在 Powershell 中捕获 Windows 窗体关闭事件

c# - IIS Express 与 dotnet 运行