Dotnet watch run - 强制重新加载以处理“粗暴编辑” - .Net 6

12
我会像这样运行Web项目,在开发过程中:

我像这样运行Web项目,在开发过程中:

dotnet watch run

项目/浏览器在我进行更改时重新加载。很棒!但有时会显示以下内容:
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)?

有没有可以添加到命令行的内容,以便强制使用总是 (a)选项?

类似这样:

dotnet watch run --AlwaysRestartOnRudeEdit

根据我的搜索,似乎并不存在这样的选项 - 不过我希望得到确认。 :)
3个回答

10

目前还没有。这样的功能已经合并到了.NET 6.0.2更新中。发布后,可以通过设置一个名为DOTNET_WATCH_RESTART_ON_RUDE_EDIT的环境变量为true来强制执行此行为。

来源:aspnetcore问题#37190

在此之前,用户eknkc发布了一个可能的解决方法(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

https://stackoverflow.com/a/76552641/10565375 这个链接提供的解决方案更简单。 - undefined

3

尝试这个 optiondotnet watch(从.NET 7开始)

dotnet watch --non-interactive

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.

当发生粗鲁的编辑时,它将重新启动:

由于粗鲁的编辑,无法应用热重载。
dotnet watch ⌚ 已退出
构建中...


1

创建一个名为DOTNET_WATCH_RESTART_ON_RUDE_EDIT的环境变量并将其设置为true。然后像往常一样运行dotnet watch


这对我有用。确保在添加环境变量后重新启动终端(如果您从Visual Studio启动终端,则还需要重新启动Visual Studio)。 - Conman_123
3
这是环境变量部分的文档链接,供参考:https://learn.microsoft.com/zh-cn/dotnet/core/tools/dotnet-watch#environment-variables - Simon_Weaver

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接