You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022中Blazor项目Hot Reload无法检测代码变更求助

Blazor Web Server项目VS2022调试时Hot Reload无法检测代码变更

近期在VS2022(17.3.3)中调试Blazor Web Server项目时,Hot Reload无法检测到代码变更,左下角持续显示"No code changes detected"。此前项目运行正常,仅做了以下两项修改:

  • 关闭了Tools / Options / Debugging, General中的"Enable Diagnostic Tools while debugging"选项
  • 在项目文件中添加了如下配置以提升Blazor组件的Intellisense速度:
<Target Name="DisableAnalyzers" BeforeTargets="CoreCompile" Condition="'$(DesignTimeBuild)' == 'true'">
    <ItemGroup>
        <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'Microsoft.NET.Sdk.Razor.SourceGenerators'" />
        <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'System.Text.Json.SourceGeneration'" />
        <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'Microsoft.Extensions.Logging.Generators'" />
    </ItemGroup>
</Target>

可能的修复方案

1. 调整项目文件中的分析器禁用配置

Blazor的Hot Reload功能依赖Microsoft.NET.Sdk.Razor.SourceGenerators分析器来跟踪Razor组件的变更。你当前的配置移除了这个关键分析器,即使是在设计时构建中,也可能干扰Hot Reload的变更检测逻辑。修改配置,保留该分析器:

<Target Name="DisableAnalyzers" BeforeTargets="CoreCompile" Condition="'$(DesignTimeBuild)' == 'true'">
    <ItemGroup>
        <!-- 仅移除不需要的分析器,保留Razor相关生成器 -->
        <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'System.Text.Json.SourceGeneration'" />
        <Analyzer Remove="@(Analyzer)" Condition="'%(Filename)' == 'Microsoft.Extensions.Logging.Generators'" />
    </ItemGroup>
</Target>

2. 重新启用诊断工具(可选)

虽然关闭"Enable Diagnostic Tools while debugging"看似与Hot Reload无关,但部分调试关联功能可能依赖此设置。尝试重新启用该选项,重启VS后再测试Hot Reload是否恢复正常。

3. 清理项目缓存并重新生成

删除项目的bin和obj文件夹,然后重新生成项目,清除可能存在的构建缓存导致的异常。

4. 检查Hot Reload相关设置

确认以下设置是否开启:

  • 路径:Tools / Options / Projects and Solutions / ASP.NET Core,确保"Enable Hot Reload on file save"已勾选
  • 右键项目 -> 属性 -> 调试,确保"启用热重载"选项处于开启状态

内容的提问来源于stack exchange,提问作者Jay Imerman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 10:25:20