MSB4018 IOException cannot access the file because it is being used by another process
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Describe the bug
Our CI builds intermittently have build failure `MSB4018: System.IO.IOException` with the following logs using the same code but different SDKs.
SDK 8.0.303. Often this file, but sometimes certain output dlls are "being used by another process". Happens seldomly.
```
/usr/lib64/dotnet/sdk/8.0.303/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/home/runner/_work/proje/proje.csproj]
/usr/lib64/dotnet/sdk/8.0.303/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018: System.IO.IOException: The process cannot access the file '/home/runner/_work/proje/bin/Release/net8.0/linux-x64/proje.deps.json' because it is being used by another process. [/home/runner/_work/proje/proje.csproj]
```
SDK 10.0.101. Always fails on this particular file. It happens very often with the .NET 10 SDK.
```
/usr/lib64/dotnet/sdk/10.0.101/Sdks/Microsoft.NET.Sdk.StaticWebAssets/targets/Microsoft.NET.Sdk.StaticWebAssets.targets(684,5): error MSB4018: The "DefineStaticWebAssets" task failed unexpectedly. [/home/runner/_work/proje/proje.csproj]
/usr/lib64/dotnet/sdk/10.0.101/Sdks/Microsoft.NET.Sdk.StaticWebAssets/targets/Microsoft.NET.Sdk.StaticWebAssets.targets(684,5): error MSB4018: System.IO.IOException: The process cannot access the file '/home/runner/_work/proje/obj/Release/net10.0/linux-x64/rpswa.dswa.cache.json' because it is being used by another process. [/home/runner/_work/proje/proje.csproj]
```
The builds are running on enterprise GHA runners within a linux docker container.
The project setup is as follows: `proja` references `projb` which references `proje`.
```
proja.csproj (library)
projb.csproj (library)
proje.csproj (Web SDK exe)
```
The build is run using `dotnet publish proja.csproj -c Release -r linux-x64`. Unfortunately I've only seen this problem on the CI builds. It hasn't happened locally.
However, when I built it locally and output the binlog, I noticed that `proje.csproj` appears to be built twice. Is it possible that this can happen in parallel?
There's work being done to allow getting the binlog from our CI, but that picture is from a small repro I created that likely exhibits the same problem. Here's the repro I created:
[exe-build-repro.zip](https://github.com/user-attachments/files/24634132/exe-build-repro.zip)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.