10

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

Kjensen
  • 12,447
  • 36
  • 109
  • 171

3 Answers3

11

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
M Bos
  • 126
  • 1
  • 4
2

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

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • This worked for me. Make sure you restart your terminal after adding the environment variable (and if you started the terminal from Visual Studio, you need to restart Visual Studio as well) – Conman_123 Jan 18 '23 at 05:55
  • 2
    Here's the environmental variables section from the docs for reference: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-watch#environment-variables – Simon_Weaver Jun 25 '23 at 22:29
2

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

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689