如何消除.NET5WPF程序中的警告NETSDK1137?
我在曾经为 .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 Filesdotnetsdk5.0.100SdksMicrosoft.NET.SdktargetsMicrosoft.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 SDKProject 元素似乎不是Microsoft.NET.Sdk应该放置替换的点。
如何消除此警告的原因?
回答
您的项目、.csproj文件,而不是 MsBuild 目标 xml。将顶行更改为以下内容:
<Project Sdk="Microsoft.NET.Sdk">