dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.74k stars 1.07k forks source link

Stable CS2012 (`The process cannot access the file`) on first build with 8.0.10 release #44080

Open MaceWindu opened 1 month ago

MaceWindu commented 1 month ago

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

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

dotnet-issue-labeler[bot] commented 1 month ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 1 month ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

MaceWindu commented 1 month ago

Small update. Noticed recently that issue is gone, so I've retested commit from time of issue creation:

https://github.com/linq2db/linq2db/tree/165762c6252dd53c6da5dc5f39b85bfaddcbd911 - this commit still fails

Reason why it works now is that we switched to .NET 9 SDK previews for build

MaceWindu commented 1 month ago

Actually it is also happens with SDK 9 RC.2, but not on every run:

c:\GitHub\linq2db>dotnet build
Restore complete (14.2s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  CodeGenerators netstandard2.0 failed with 1 error(s) (6.8s)
    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\CodeGenerators\Debug\CodeGenerators.dll' because it is being used by another process.'
  CodeGenerators succeeded (5.2s) → .build\bin\CodeGenerators\Debug\CodeGenerators.dll