node.js – dotnet core并行或同时构建

前端之家收集整理的这篇文章主要介绍了node.js – dotnet core并行或同时构建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
this解决方案中我有2个应用程序:AppA,AppB共享类库Shared.我已尝试与 PowerShellnode脚本并行地自动构建/运行这些脚本(我会对其他解决方案持开放态度).我正在使用–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

节点:
运行项目构建脚本或节点./build-script/app.js

为什么共享项目甚至使用–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.

您可以使用msbuild,而不是使用Start-Process来实现并行构建,它支持开箱即用.

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.csproj和AppB.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>

猜你在找的.NET Core相关文章