简体   繁体   English

在 Visual Studio 2019 中禁用 .NET 核心项目的热重载

[英]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:您在此下拉列表中的选项如下:

  1. None没有任何
  2. Auto build on browser request (IIS only)根据浏览器请求自动构建(仅限 IIS)
  3. Refresh browser after build构建后刷新浏览器
  4. Auto build and refresh browser after saving changes保存更改后自动构建和刷新浏览器

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:这些屏幕截图显示了一种访问设置的方法:

Visual Studio 调试菜单

Visual Studio 调试配置文件

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   <===========
    }
  }
}```

I have the same problem, go to Tools > Options > Debugging > General我有同样的问题,go 到工具 > 选项 > 调试 > 常规

and check this option Enable edit and continue and hot reload并选中此选项Enable edit and continue and hot reload

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 2019 中将 .NET Framework 4.7.2 项目迁移到 .NET Core 3.0 - How to migrate .NET Framework 4.7.2 project to .NET Core 3.0 in Visual Studio 2019 Visual Studio 2019 - msvsmon.exe 意外退出。 .net 核心 1.1 项目将中止调试 - Visual Studio 2019 - msvsmon.exe unexpectedly exited. Debugging will be aborted with .net core 1.1 project 安装最新版VS Visual Studio 2019 16.4后无法加载项目.net core 3.0 - Can not load project .net core 3.0 after install the latest version of VS Visual Studio 2019 version 16.4 Visual Studio 2019 Enterprise上未显示ASP.NET Core 3.0 - ASP.NET Core 3.0 not showing on Visual Studio 2019 Enterprise Dot Net Core 3.1 未出现在 Visual Studio 2019 中 - Dot Net Core 3.1 does not show up in Visual Studio 2019 Visual Studio 中 .net 核心项目的锁定文件 - locked files of .net core project in Visual Studio 如何将 .Net 框架添加到 Visual Studio preview 2019 项目 - How to add .Net framework to Visual Studio preview 2019 project Typescript 的热重载在 Visual Studio 2022 中的 Razor class 库中编译 - Hot reload for Typescript compile in Razor class library in Visual Studio 2022 如何使用 Visual Studio 2019 中的控制台项目测试 .net 5 WPF 项目? - How can I test a .net 5 WPF project using a console project in Visual Studio 2019? 如何为.NET Core创建Visual Studio 2015项目模板? - How to create a Visual Studio 2015 project template for NET Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM