wpf - 如何消除 .NET 5 WPF 程序中的警告 NETSDK1137?

标签 wpf .net-5

我在曾经为 .NET Framework 4.5 构建但现在正在为 .NET 5 构建的 WPF 程序中有以下警告。

Warning NETSDK1137  It is no longer necessary to use the Microsoft.NET.Sdk.WindowsDesktop SDK. 
    
Consider changing the Sdk attribute of the root Project element to 'Microsoft.NET.Sdk'. 
    
ListEditor 

C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets   376 
单击警告打开文件 Microsoft.NET.Sdk.DefaultItems.targets在第 376 行。该文件以 DO NOT MODIFY 的注释开头。 .
<!--
***********************************************************************************************
Microsoft.NET.Sdk.DefaultItems.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved. 
***********************************************************************************************
-->
第 376 行位于此 XML 元素中...
  <Target Name="_CheckForUnnecessaryWindowsDesktopSDK"
        BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
        Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '5.0')) and '$(_MicrosoftWindowsDesktopSdkImported)' == 'true' and '$(TargetFrameworks)' == ''">
    <NETSdkWarning ResourceName="UnnecessaryWindowsDesktopSDK" />
  </Target>
有一个包含整个文件的 Project 元素。元素是这个...
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    ...omissions...
</Project>
由于该元素未提及 Microsoft.NET.Sdk.WindowsDesktop SDK Project 元素似乎不是替换 Microsoft.NET.Sdk 的点应该放置。
如何消除此警告的原因?

最佳答案

您的项目,.csproj文件,而不是 MsBuild 目标 xml。将顶行更改为以下内容:

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

关于wpf - 如何消除 .NET 5 WPF 程序中的警告 NETSDK1137?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65740064/

相关文章:

c# - WPF 使用鼠标和触摸与 Adorner 一起拖放

c# - 如何将参数传递给通用操作过滤器

c# - 在.net5 Preview5中启用C#9会为新的C#9功能引发编译器错误

wpf - 不选择任何项目启动 ListView

c# - GridViewColumn autosize 只工作一次

c# - 如何使用 FluentValidation 在 IValidateOptions 中编写流畅的验证规则?

c# - 如何强制删除Asp.net core中另一个进程使用的文件

.net-core - .NET Core 3.1 应用程序不再构建在 Azure 管道上 (.NET 5)

wpf - 如何使用 MVVM 应用程序在 WPF 中以编程方式设置 DataGrid 的选定项?

c# - Expander IsExpanded 绑定(bind)