Search code examples
.net-6.0dotnet-clidotnet-watch

Dotnet watch run - Force reload on "rude edit" - .Net 6


I run web projects like this, during development:

dotnet watch run

The project/browser reloads when I make a change. Awesome!

However, sometimes I will be shown this:

Unable to apply hot reload because of a rude edit.
Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?

Is there something I can add to the commandline, so I force the Always (a) option?

Something like this:

dotnet watch run --AlwaysRestartOnRudeEdit

According to my google-fu/duckduck-fu, such an option does not exist - but I would like it confirmed. :)


Solution

  • Not yet. A feature like that has been merged into the .NET 6.0.2 update. Once released, it will be possible to force this behavior by setting an environment variable named DOTNET_WATCH_RESTART_ON_RUDE_EDIT to true.

    Source: aspnetcore issue #37190

    Until then, user eknkc posted a possible workaround (Unix):

    #!/usr/bin/env expect -f
    
    set timeout -1
    spawn dotnet watch run
    expect  "Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?\r"
    send -- "a"
    expect eof