5

WPF 修复 dotnet 6 与源代码包冲突

 2 years ago
source link: https://lindexi.gitee.io/post/WPF-%E4%BF%AE%E5%A4%8D-dotnet-6-%E4%B8%8E%E6%BA%90%E4%BB%A3%E7%A0%81%E5%8C%85%E5%86%B2%E7%AA%81.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

WPF 修复 dotnet 6 与源代码包冲突

在 dotnet 6 时,官方为了适配好 Source Generators 功能,于是默认就将 WPF 的 XAML 构建过程中,引入第三方库的 cs 文件,这个功能默认设置为开启。刚好源代码包为了修复在使用 dotnet 6 SDK 之前,在 WPF 的构建 XAML 过程中,不包含第三方库的代码文件,从而使用黑科技将源代码包加入到 WPF 构建 XAML 中。在 VisualStudio 升级到 2022 版本,或者是升级 dotnet sdk 到 dotnet 6 版本,将会更新构建调度,让源代码包里的代码文件被加入两次,从而构建失败

修复方法很简单,在不更改源代码包的前提下,可以在 csproj 项目文件里加入以下代码

    <IncludePackageReferencesDuringMarkupCompilation>False</IncludePackageReferencesDuringMarkupCompilation>

更改之后的 csproj 代码如下

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <IncludePackageReferencesDuringMarkupCompilation>False</IncludePackageReferencesDuringMarkupCompilation>
  </PropertyGroup>

</Project>

此影响不仅包含 TargetFramework 为 net6.0-windows 的 WPF 应用,而是任何使用 SDK 风格的 WPF 项目。其原因是 dotnet 6 此更改是在 dotnet sdk 更改构建调度过程,和具体应用的框架无关,只影响构建本身

lindexi%2F202112291523193526.jpg

更多关于 WPF 构建过程,请看 WPF 程序的编译过程 - walterlv


本文会经常更新,请阅读原文: https://blog.lindexi.com/post/WPF-%E4%BF%AE%E5%A4%8D-dotnet-6-%E4%B8%8E%E6%BA%90%E4%BB%A3%E7%A0%81%E5%8C%85%E5%86%B2%E7%AA%81.html ,以避免陈旧错误知识的误导,同时有更好的阅读体验。

如果你想持续阅读我的最新博客,请点击 RSS 订阅,推荐使用RSS Stalker订阅博客,或者前往 CSDN 关注我的主页

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请 与我联系

无盈利,不卖课,做纯粹的技术博客

以下是广告时间

推荐关注 Edi.Wang 的公众号
lindexi%2F201985113622445

欢迎进入 Eleven 老师组建的 .NET 社区
lindexi%2F20209121930471745.jpg

以上广告全是友情推广,无盈利


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK