The dotnet kernel is created in parallel or simultaneously.

To this solution I have 2 applications: AppA , AppB , which share the Shared class library. I tried to automate the build / run of these files in parallel with PowerShell and node (I would be open to other solutions). I use the --no-dependencies and --no-restore flags, but with interruptions I get:

 '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' 

PowerShell:. /build.ps1 enter image description here

node: run a build-script or node ./build-script/app.js enter image description here

Why is a Shared project created even with the --no-dependencies flag? How can I build in parallel or simultaneously?

+5
source share
1 answer

Explanation for CS2012 Error: The process cannot access the file.

I could reproduce your problem and Process Monitor shows that both processes open shared.dll at the same time for reading. This leads to the problem you described.

Although reading the same file from different processes can be done using FileShare.Read , as the documentation indicates (see excerpt below), it seems that this is NOT done by csc.exe . This is a flaw of csc.exe , which probably will not change in the near future.

Allows you to continue opening the file for reading. If this flag is not specified, any request to open a file for reading (by this process or another process) will fail with an error until the file is closed. However, even if this flag is specified, additional permissions may be available to access the file.

Decision

Instead of using the Start-Process to achieve parallel builds, you can use msbuild, which supports this out of the box.

Parallel builds are supported by msbuild with the /maxcpucount -switch and BuildInParallel -task options, as described in the MS Build Documentation .

Parallel assembly is enabled using /maxcpucount -switch at the command line:

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

In addition, you must also use the BuildInParallel -task parameter in the ParallelBuildAB.csproj project file. Please note that AppA.csproj and AppB.csproj include:

 <?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> 
+3
source

Source: https://habr.com/ru/post/1274205/


All Articles