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

3.6k Views Asked by At

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. :)

3

There are 3 best solutions below

1
On BEST ANSWER

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
2
On

Create an environment variable DOTNET_WATCH_RESTART_ON_RUDE_EDIT set to true. The run dotnet watch like normal.

0
On

Try this option for dotnet watch (from .NET 7 onwards)

dotnet watch --non-interactive

From dotnet watch --help:

--non-interactive Runs dotnet-watch in non-interactive mode. 
This option is only supported when running with Hot Reload enabled. 
Use this option to prevent console input from being captured.

It will restart when a rude edit occurs:

dotnet watch ⌚ Unable to apply hot reload because of a rude edit.
dotnet watch ⌚ Exited dotnet watch
Building...