Stable CS2012 (`The process cannot access the file`) on first build with 8.0.10 release
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
### Describe the bug
After 8.0.10 release this week our builds stopped to work with
```
CSC : error CS2012: Cannot open '.build\obj\CodeGenerators\Azure\CodeGenerators.dll' for writing -- 'The process cannot access the file '.build\obj\Code
Generators\Azure\CodeGenerators.dll' because it is being used by another process.'
```
error, where `CodeGenerators` is roslyn code-generators project.
### To Reproduce
Checkout source from https://github.com/linq2db/linq2db and run following build command
```
dotnet build --configuration Debug
```
It will fail with error.
```
c:\GitHub\linq2db>dotnet build --configuration Debug
Determining projects to restore...
Restored c:\GitHub\linq2db\Source\CodeGenerators\CodeGenerators.csproj (in 1.6 sec).
Restored c:\GitHub\linq2db\Source\LinqToDB\LinqToDB.csproj (in 1.62 sec).
Restored c:\GitHub\linq2db\Source\LinqToDB.FSharp\LinqToDB.FSharp.fsproj (in 1.62 sec).
Restored c:\GitHub\linq2db\Source\LinqToDB.Extensions\LinqToDB.Extensions.csproj (in 1.62 sec).
Restored c:\GitHub\linq2db\Tests\FSharp\Tests.FSharp.fsproj (in 1.65 sec).
Restored c:\GitHub\linq2db\Source\LinqToDB.EntityFrameworkCore\LinqToDB.EntityFrameworkCore.csproj (in 1.64 sec).
Restored c:\GitHub\linq2db\Source\LinqToDB.Remote.Wcf\LinqToDB.Remote.Wcf.csproj (in 6 ms).
Restored c:\GitHub\linq2db\Source\LinqToDB.Tools\LinqToDB.Tools.csproj (in 90 ms).
Restored c:\GitHub\linq2db\Tests\Base\Tests.Base.csproj (in 55 ms).
Restored c:\GitHub\linq2db\Tests\EntityFrameworkCore.FSharp\Tests.EntityFrameworkCore.FSharp.fsproj (in 1.65 sec).
Restored c:\GitHub\linq2db\Tests\VisualBasic\Tests.VisualBasic.vbproj (in 59 ms).
Restored c:\GitHub\linq2db\Source\LinqToDB.Remote.Grpc\LinqToDB.Remote.Grpc.csproj (in 1.98 sec).
Restored c:\GitHub\linq2db\Tests\Model\Tests.Model.csproj (in 45 ms).
Restored c:\GitHub\linq2db\Tests\EntityFrameworkCore\Tests.EntityFrameworkCore.csproj (in 1.01 sec).
Restored c:\GitHub\linq2db\Source\LinqToDB.CLI\LinqToDB.CLI.csproj (in 943 ms).
Restored c:\GitHub\linq2db\Tests\Tests.Benchmarks\linq2db.Benchmarks.csproj (in 800 ms).
Restored c:\GitHub\linq2db\Tests\Tests.T4\Tests.T4.csproj (in 846 ms).
Restored c:\GitHub\linq2db\Tests\Tests.Playground\Tests.Playground.csproj (in 805 ms).
Restored c:\GitHub\linq2db\Tests\Linq\Tests.csproj (in 1.06 sec).
CSC : error CS2012: Cannot open 'c:\GitHub\linq2db\.build\obj\CodeGenerators\Debug\CodeGenerators.dll' for writing -- 'The process cannot access the file 'c:\GitHub\linq2db\.build\obj\Code
Generators\Debug\CodeGenerators.dll' because it is being used by another process.' [c:\GitHub\linq2db\Source\CodeGenerators\CodeGenerators.csproj]
CodeGenerators -> c:\GitHub\linq2db\.build\bin\CodeGenerators\Debug\CodeGenerators.dll
```
Second build will succeed (if you don't remove .build with files from previous attempt).
While locally we can rerun build, on CI it is more problematic.
### Further technical details
- Include the output of `dotnet --info`
```
c:\GitHub\linq2db>dotnet --info
.NET SDK:
Version: 8.0.403
Commit: c64aa40a71
Workload version: 8.0.400-manifests.e99c892e
MSBuild version: 17.11.9+a69bbaaf5
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.403\
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[aspire]
Installation Source: VS 17.11.35327.3
Manifest Version: 8.1.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.10
Architecture: x64
Commit: 81cabf2857
.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
6.0.315 [C:\Program Files\dotnet\sdk]
8.0.403 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.35 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
arm64 [C:\Program Files\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
c:\GitHub\linq2db\global.json
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
Contributor guide
Research direction
Start with Source/CodeGenerators/CodeGenerators.csproj and the .build output while running dotnet build --configuration Debug on Windows with SDK 8.0.403. Compare the first and second builds to investigate why CodeGenerators.dll remains locked. Done means a clean first build succeeds reliably, including on CI.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100