You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a project references a custom Source Generator, changes to the project while using dotnet watch can cause warning MSB3026, error MSB3027, and error MSB3021. This is due to the source generator project's output DLL being locked.
To Reproduce
I've created a repro at https://github.com/bdukes/lockrepro. There's a script which starts dotnet watch and then switches branches to simulate making changes to the files.
Exceptions (if any)
Error output
dotnet watch ⌚ File changed: .\MyExample.WidgetApi\MyExample.WidgetApi.csproj.
dotnet watch ⌚ Exited
dotnet watch 🔧 Building...
MyExample.ThisIsASourceGenerator failed with 2 error(s) and 10 warning(s) (12.8s)
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 2 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 3 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 4 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 6 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 7 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 8 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 9 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): warning MSB3026: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.This
IsASourceGenerator.dll". Beginning retry 10 in 1000ms. The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): error MSB3027: Could not copy "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll". Exceeded retry count of 10. Failed. The file is locked by: ".NET Host (20364)"
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(4806,5): error MSB3021: Unable to copy file "obj\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll" to "bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll". The process cannot access the file 'I:\code\lockrepro\MyExample.ThisIsASourceGenerator\bin\Any CPU\Debug\net8.0\MyExample.ThisIsASourceGenerator.dll' because it is being used by another process.
Build failed with 2 error(s) and 10 warning(s) in 14.1s
Describe the bug
When a project references a custom Source Generator, changes to the project while using
dotnet watch
can cause warning MSB3026, error MSB3027, and error MSB3021. This is due to the source generator project's output DLL being locked.To Reproduce
I've created a repro at https://github.com/bdukes/lockrepro. There's a script which starts
dotnet watch
and then switches branches to simulate making changes to the files.Exceptions (if any)
Error output
Further technical details
dotnet --info
The text was updated successfully, but these errors were encountered: