sdk: Builds of solutions with multiple inter-dependent .NET Core projects frequently fail with CS2012 "Cannot open" file errors

Steps to reproduce

With a solution with multiple .NET Core projects with many sharing project dependencies:

  • dotnet restore
  • dotnet build

Expected behavior

Solution builds.

Actual behavior

Solution sometimes builds, but also often fails with errors similar to:

CSC : error CS2012: Cannot open 'C:\a\w\1\s\src\Project\obj\Debug\netstandard1.4\Project.dll' for writing -- 'The process cannot access the file 'C:\a\w\1\s\src\Project\obj\Debug\netstandard1.4\Project.dll' because it is being used by another process.'

Sometimes there are warnings:

warning MSB3026: Could not copy "obj\Debug\netstandard1.4\Project.dll" to "bin\Debug\netstandard1.4\Project.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\a\w\1\s\src\Project\bin\Debug\netstandard1.4\Project.dll' because it is being used by another process. [C:\a\w\1\s\src\Project\Project.csproj]

Errors and warnings can occur for different projects.

Switching from dotnet build to msbuild /maxcpucount:1 avoids the problems.

The errors occur more frequently on build servers (Azure VMs, Standard F2S) than on laptop (i7-5600U, 16GB, SSD).

Our build script replaces version numbers in AssemblyInfo.cs files, so many projects are rebuilt on every build.

Executing dotnet build --no-incremental also seems to increase failure rate locally (where otherwise repeated builds may not build all projects).

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview3-004056)

Product Information:
 Version:            1.0.0-preview3-004056
 Commit SHA-1 hash:  ccc4968bc3

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

Well it’s really easy to reproduce with NET SDK 2.0.2

dotnet publish -o /home/user/publish_dir 

Will publish everything from a solution into one folder in case argument of -o is an absolute directory. This is super convenient and a way to go in case you make sure projects are compatible. Though publish commands can fight for files of course.

this still occurs in 2.1.1, linux. fails sometimes when running the dotnet test, happens mostly on our builder machine but not only

It is not fixed on 1.0.4 on Linux as well