Source Generators doesn't work well with dotnet watch (OSOE-1203)
When using dotnet watch on a project where the Source Generator is added as part of the HL submodule, and I make a "rude edit" that makes the watcher build the solution, it will fail and stuck with this error:
C:\Program Files\dotnet\sdk\8.0.416\Microsoft.Common.CurrentVersion.targets(4857,5): warning MSB3026: Could not copy "obj\Debug\netstandard2.0\Lombiq.HelpfulLibraries.SourceGenerators.dll" to "bin\Debu
g\netstandard2.0\Lombiq.HelpfulLibraries.SourceGenerators.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'D:\Repos\Lombiq\LMBQ\src\Libraries\Lombiq.HelpfulLibraries\Lombiq.Helpfu
lLibraries.SourceGenerators\bin\Debug\netstandard2.0\Lombiq.HelpfulLibraries.SourceGenerators.dll' because it is being used by another process. The file is locked by: ".NET Host (13424)" [D:\Repos\Lomb
iq\LMBQ\src\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.SourceGenerators\Lombiq.HelpfulLibraries.SourceGenerators.csproj]
I don't know if we can do anything with this, given that the process locking the file is also .NET.
What is a "rude edit"?
What is a "rude edit"?
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-watch#rude-edits
This is what I do:
-
dotnet watchin src\Lombiq.OSOCE.Web. - Open https://localhost:5001/ and set up the site with the OSOCE recipe.
- Open https://localhost:5001/UIKitShowcase.
- Edit src\Modules\Lombiq.UIKit\Lombiq.UIKit\Views_ViewImports.cshtml in Notepad++ by removing the
@addTagHelper *, OrchardCore.DisplayManagementline. -
dotnet watchrecognizes the edit and reloads the app:
Note that while I was doing this, there was indeed nothing else going on. E.g., I didn't have the solution open in VS,
This is not a "rude edit", unfortunately. When a rude edit happens, you need to see a prompt that asks you what to want - rebuild, ignore, etc. At this point I'm a bit confused what counts a rude edit and where, for me _ViewImports counted as one, for you, it didn't. Can you please play around until you see the prompt? Here, you need to pick Restart.
OK, editing src\Modules\Lombiq.ContentEditors\Lombiq.ContentEditors\Manifest.cs by removing line 19 triggered this, and I see it too:
So this is absolutely not reproducible for you @sarahelsaig , right?
Works for me on Linux! 🐧🍰
What kind of changes in which cshtml files trigger this for you, exactly, @barthamark? Please provide a concrete file-change combination.
Also, this might be fixed by .NET 10. Related bug that explains that this started with .NET 8: https://github.com/dotnet/sdk/issues/35607.
The focus is not on cshtml changes as triggers but anything that counts as rude edits as trigger. Thanks for finding the bug report, it looks related, and might wort waiting for that fix.
By the way, adding a new cshtml to a theme typically triggers rude edit.
This is important because an angle to this problem is that since this only comes up with rude edits, if you avoid those, there's no problem. (Understanding that this is most interesting for cshtml edits, we might figure out how to avoid those being rude edits.) We've seen that what counts as a rude edit is not obvious, as the same kind of files can be either, perhaps depending on the development environment too, but I don't yet understand why. So this is why I'm asking you for an example.