排查 XAML 热重载问题Troubleshooting XAML Hot Reload
09/04/2019
本文内容
此故障排除指南包括的详细说明应解决阻止 XAML 热重载正常工作的大多数问题。This troubleshooting guide includes detailed instructions that should resolve most issues that prevent XAML Hot Reload from working correctly.
WPF 和 UWP 应用支持 XAML 热重载。XAML Hot Reload is supported for WPF and UWP apps. For details on operating system and tooling requirements, see Write and debug running XAML code with XAML Hot Reload.
热重载不可用Hot Reload is not available
调试应用时,如果在应用内工具栏中看到消息 "热重载不可用",请按照本文中所述的说明解决此问题。If you see the message "Hot Reload is not available" in the in-app toolbar while debugging your app, follow the instructions described in this article to resolve the issue.
验证是否启用了 XAML 热重载Verify that XAML Hot Reload is enabled
默认情况下启用此功能。The feature is enabled by default. 开始调试应用时,请确保看到应用内工具栏,该工具栏确认 XAML 热重载可用:When you start debugging your app, make sure you see the in-app toolbar, which confirms that XAML Hot Reload is available:
如果看不到应用内工具栏,请打开 "常规调试 > 选项" > General。If you do not see the in-app toolbar, then open Debug > Options > General. 请确保选择 " 启用 xaml 的 UI 调试工具 并 启用 xaml 热重载 " 这两个选项。Make sure that both options, Enable UI Debugging Tools for XAML and Enable XAML Hot Reload are selected.
如果选择这些选项,则请在 " (调试 > Windows > 实时可视化) 树) " 中,选择 "打开",并确保已选中 "在应用程序工具栏按钮中显示运行时工具 ("。If these options are selected, then go to Live Visual Tree (Debug > Windows > Live Visual Tree) and make sure that Show runtime tools in application toolbar button (on the far left) is selected.
验证是否使用 "启动调试" 而不是 "附加到进程"Verify that you use Start Debugging rather than Attach to Process
XAML 热重载要求在 ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO 应用程序启动时将环境变量设置为1。XAML Hot Reload requires that the environment variable ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO is set to 1 at the time application starts. Visual Studio 会自动将其设置为调试 > 开始调试 (或F5) 命令。Visual Studio sets this automatically as part of the Debug > Start Debugging (or F5) command. 如果要将 XAML 热重载与Debug > Attach to Process命令一起使用,则需自行设置环境变量。If you want to use XAML Hot Reload with the Debug > Attach to Process command instead, then set the environment variable yourself.
备注
若要设置环境变量,请使用 "开始" 按钮搜索 "环境变量",然后选择 " 编辑系统环境变量"。To set an environment variable, use the Start button to search for "environment variable" and choose Edit the system environment variables. 在打开的对话框中,选择 " 环境变量",然后将其添加为用户变量,并将值设置为 1 。In the dialog box that opens, choose Environment Variables, then add it as a user variable, and set the value to 1. 若要清理,请在完成调试后删除变量。To clean up, remove the variable when you are finished debugging.
验证 MSBuild 属性是否正确Verify that your MSBuild properties are correct
默认情况下,调试配置中包含源信息。By default, source info is included in a Debug configuration. 它由项目文件中的 MSBuild 属性控制 (如 * .csproj) 。It is controlled by MSBuild properties in your project files (such as *.csproj). 对于 WPF,属性是 XamlDebuggingInformation ,它必须设置为 True 。For WPF, the property is XamlDebuggingInformation, which must be set to True. 对于 UWP,属性为 DisableXbfLineInfo ,它必须设置为 False 。For UWP, the property is DisableXbfLineInfo, which must be set to False. 例如:For example:
WPF:WPF:
True
UWPUWP:
False
验证您使用的是正确的生成配置名称Verify that you are using the correct build configuration name
必须手动设置正确的 MSBuild 属性以支持 XAML 热重载 (请参阅上一节) ,或者必须使用 (调试) 的默认生成配置名称。You must either manually set the correct MSBuild property to support XAML Hot Reload (see previous section), or you must use the default build configuration name (Debug). 如果未正确设置 MSBuild 属性,自定义生成配置名称将不起作用,也不会发布版本。If you don't set the MSBuild property correctly, a custom build configuration name won't work, nor will a Release build.
验证你的 XAML 文件没有错误Verify that your XAML file has no errors
如果 XAML 文件在 错误列表中显示错误,则 Xaml 热重载可能不起作用。If your XAML file shows errors in the Error List, then XAML Hot Reload may not work.
另请参阅See also



