首页 > 解决方案 > 如何将 XamlDebuggingInformation MSBuild 属性添加到 CsProj?

问题描述

微软关于 XAML 热重载故障排除的这个页面是这样说的:

默认情况下,源信息包含在调试配置中。它由项目文件(例如 *.csproj)中的 MSBuild 属性控制。对于 WPF,该属性是 XamlDebuggingInformation,必须设置为 True。对于 UWP,该属性为 DisableXbfLineInfo,必须设置为 False。例如:

WPF:<XamlDebuggingInformation>True</XamlDebuggingInformation>

超轻量级:<DisableXbfLineInfo>False</DisableXbfLineInfo>

由于我的项目配置名称不是“调试”,因此热重载属性不会自动出现在我的 MSBuild 配置中,正如您所见,Microsoft 建议我添加XamlDebuggingInformation到我的 .csProj 以使 XAML 热重载工作但我不知道如何要做到这一点。

我尝试在具有我想要应用的配置的标签中添加一个新行<PropertyGroup>,但之后 Visual Studio 很难加载。如何添加此 MSBuild 属性?

csproj 文件示例

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{1EA7A7EC-D092-4DE3-B8DD-49F74B71ACF2}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <RootNamespace>PatchDeDup</RootNamespace>
    <AssemblyName>PatchDeDup</AssemblyName>
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <WarningLevel>4</WarningLevel>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'OtherDebug|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\OtherDebug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  ... file includes, dependency references, etc. (pretty generic wpf project stuff)

我以为我必须<XamlDebuggingInformation>True</XamlDebuggingInformation>PropertyGroupfor中添加,OtherDebug|AnyCPU但 VS 2019 显然并不期望...

标签: wpfvisual-studioxamlmsbuildcsproj

解决方案


我的解决方案最终变得非常简单。打开.csProj文件,找到PropertyGroup具有您期望的配置名称的文件,并将其添加<XamlDebuggingInformation>True</XamlDebuggingInformation>到 XML 标记的正文中。

对我来说,我不得不在 Visual Studio 关闭时执行此操作,因为解决方案重新加载失败并且 Visual Studio 陷入了无限循环。但是在打开之前添加它很好:)


推荐阅读