Dotnet CLI 热重载:在粗鲁的编辑时总是重新启动应用程序?

Max*_*Max 16 .net asp.net dotnet-cli hot-reload

在 .NET CLI 中使用热重载时...

$ dotnet watch
watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.
watch : Building...
  ...
watch : Started

Run Code Online (Sandbox Code Playgroud)

...任何粗鲁的编辑都会导致以下提示:

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

有没有办法告诉 CLI 默认为“始终”?就像是dotnet watch --always-restart

(询问是因为我想dotnet watch在容器中运行)

Max*_*Max 13

事实证明,是的

$ export DOTNET_WATCH_RESTART_ON_RUDE_EDIT=1
$ dotnet watch
Run Code Online (Sandbox Code Playgroud)

(.NET 6.0.2+)

  • 呵呵,如果我在 Windows 中设置 DOTNET_WATCH_RESTART_ON_RUDE_EDIT=1 ,这似乎不起作用。我至少可以选择始终重新加载,但我无法让“dotnet watch”的默认行为始终重新加载。有人知道我可能做错了什么吗?我的机器没有“导出”cmd(win11 cmder/cmd)。 (3认同)

Rag*_*use 6

也可以传递非交互式标志:

dotnet watch run --non-interactive
Run Code Online (Sandbox Code Playgroud)

--non-interactive

以非交互模式运行 dotnet watch。使用此选项可以防止请求控制台输入。当启用热重载并检测到粗鲁编辑时,dotnet watch 会重新启动应用程序。自 .NET 7 SDK 起可用。

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-watch#options /sf/answers/5358684901/