Helpful-Libraries icon indicating copy to clipboard operation
Helpful-Libraries copied to clipboard

Source Generators doesn't work well with dotnet watch (OSOE-1203)

Open barthamark opened this issue 3 months ago • 11 comments

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]  

Jira issue

barthamark avatar Dec 02 '25 11:12 barthamark

I don't know if we can do anything with this, given that the process locking the file is also .NET.

Piedone avatar Dec 02 '25 20:12 Piedone

What is a "rude edit"?

sarahelsaig avatar Dec 03 '25 23:12 sarahelsaig

What is a "rude edit"?

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-watch#rude-edits

barthamark avatar Dec 03 '25 23:12 barthamark

This is what I do:

  1. dotnet watch in src\Lombiq.OSOCE.Web.
  2. Open https://localhost:5001/ and set up the site with the OSOCE recipe.
  3. Open https://localhost:5001/UIKitShowcase.
  4. Edit src\Modules\Lombiq.UIKit\Lombiq.UIKit\Views_ViewImports.cshtml in Notepad++ by removing the @addTagHelper *, OrchardCore.DisplayManagement line.
  5. dotnet watch recognizes the edit and reloads the app:
Image

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,

Piedone avatar Dec 04 '25 15:12 Piedone

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.

Image

barthamark avatar Dec 04 '25 15:12 barthamark

OK, editing src\Modules\Lombiq.ContentEditors\Lombiq.ContentEditors\Manifest.cs by removing line 19 triggered this, and I see it too:

Image

Piedone avatar Dec 04 '25 16:12 Piedone

So this is absolutely not reproducible for you @sarahelsaig , right?

barthamark avatar Dec 04 '25 17:12 barthamark

Works for me on Linux! 🐧🍰

Image

sarahelsaig avatar Dec 04 '25 18:12 sarahelsaig

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.

Piedone avatar Dec 05 '25 01:12 Piedone

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.

barthamark avatar Dec 06 '25 10:12 barthamark

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.

Piedone avatar Dec 06 '25 18:12 Piedone