【问题标题】:How to debug XAML hot reload in a .Net Core 3.1 WPF app?如何在 .Net Core 3.1 WPF 应用程序中调试 XAML 热重载?
【发布时间】:2020-05-15 12:18:44
【问题描述】:

我有一个小型 WPF 测试工具应用程序,用于可视化包含在单独库中的用户控件。这两个项目都是 netcoreapp3.1 并包含在 Win10 x64 上的 VS 2019 16.4 中的同一个活动解决方案中。

(普通)测试工具中 MainWindow.xaml 的构造函数如下所示:

namespace HotReloadDemo.TestHarness
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Content = new HotReloadDemo.MainAppUnderTest.MyUserControl();
        }
    }
}

被测试的控件如下所示:

<UserControl x:Class="HotReloadDemo.MainAppUnderTest.MyUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Background="White"
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <TextBlock TextAlignment="Center" VerticalAlignment="Center" FontSize="50">This is a test</TextBlock>
    </Grid>
</UserControl>

在此设置中,热重载效果很好 - 我可以对控件进行布局更改,并且布局也会发生变化。但是,在我自己的(非演示)解决方案中,相同的设置似乎不起作用。正在调试的应用程序确实显示“热重载可用”,但可惜的是,更改控件的布局不会更新实时应用程序。

我查看了herehere,但找不到任何有用的东西。如何调试发生了什么?

【问题讨论】:

  • 感谢您与我们的工程师一起解除对您的实际项目的阻碍,我希望现在一切正常,如果您能在此处确认,那将非常适合与适合您的解决方案进行循环 :)
  • 是的,感谢您的帮助。有点晚了,但会的。

标签: c# wpf xaml hot-reload


【解决方案1】:

原来我定义了一个自定义构建配置(“DebugNoAuth”),默认隐式行为仅配置为与“发布”和“调试”一起使用。将 XamlDebuggingInformation==true 显式添加到 .csproj 属性可解决该问题。

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWPF>true</UseWPF>
... 
    <XamlDebuggingInformation>True</XamlDebuggingInformation> 
    <Configurations>Debug;Release;DebugNoAuth</Configurations>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <Platforms>AnyCPU;x64</Platforms>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <DefineConstants>TRACE;DebugNoAuth</DefineConstants>
  </PropertyGroup>

感谢 Microsoft 团队的 Dmitry 和 Evgeny 帮助调试调试器。

【讨论】:

    猜你喜欢
    • 2020-11-07
    • 1970-01-01
    • 2020-08-27
    • 2020-08-28
    • 2021-08-26
    • 1970-01-01
    • 2021-08-03
    • 2020-05-21
    • 1970-01-01
    相关资源
    最近更新 更多