[英]Disabling Hot Reload for .NET Core project in Visual Studio 2019
Some time ago, a Visual Studio update added a hot reload feature.前段时间,Visual Studio 更新添加了热重载功能。 It be handy, but it also can be annoying especially when you're testing and you don't want to reset the current state of the front end.
它很方便,但也很烦人,尤其是在您进行测试并且不想重置前端的当前 state 时。 Visual Studio injects the script whether you're debugging or not.
无论您是否在调试,Visual Studio 都会注入脚本。
How can hot reload be disabled?如何禁用热重载? My Visual Studio version is 16.10.3
我的 Visual Studio 版本是 16.10.3
https://devblogs.microsoft.com/visualstudio/speed-up-your-dotnet-and-cplusplus-development-with-hot-reload-in-visual-studio-2022/ https://devblogs.microsoft.com/visualstudio/speed-up-your-dotnet-and-cplusplus-development-with-hot-reload-in-visual-studio-2022/
You can change this feature here:您可以在此处更改此功能:
Tools > Options > Projects and Solutions > ASP.NET Core > Auto build and refresh option
Options to automatically build and refresh the browser if the web server is running when changes are made to the project.
如果对项目进行更改时 Web 服务器正在运行,则自动构建和刷新浏览器的选项。
Your options in this dropdown are the following:您在此下拉列表中的选项如下:
Also note my version of VS is 16.11.1
.另请注意,我的 VS 版本是
16.11.1
。
This isn't a great solution, but it's a viable workaround.这不是一个很好的解决方案,但它是一个可行的解决方法。
In the "Network" tab of Chromium Edge's developer tools, I found the request to load aspnetcore-browser-refresh.js
.在 Chromium Edge 开发者工具的“网络”选项卡中,我找到了加载
aspnetcore-browser-refresh.js
的请求。 I right click on it and selected "Block URL".我右键单击它并选择“阻止 URL”。 This prevents the script from loading.
这可以防止加载脚本。
使用 CLI 你必须做
dotnet watch run --no-hot-reload
In VS2022, unchecking the "Enable Hot Reload" setting under the projects Debug Properties disables the injection of the aspnetcore-browser-refresh.js
script.在 VS2022 中,取消选中项目调试属性下的“启用热重载”设置会禁用
aspnetcore-browser-refresh.js
脚本的注入。
These screenshots show one way to access the setting:这些屏幕截图显示了一种访问设置的方法:
in VS 2022 open launchSettings.json in the Properties folder在 VS 2022 中打开 Properties 文件夹中的 launchSettings.json
find your profile and add (see arrow, don't add arrow)找到您的个人资料并添加(见箭头,不要添加箭头)
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"Gang.Bingo.Web": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:7249;http://localhost:5249",
"dotnetRunMessages": true,
"hotReloadEnabled": false <===========
}
}
}```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.