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>
source share