我在曾经为 .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/