I have the following warning in a WPF program that used to be built for .NET Framework 4.5 but is now being built for .NET 5.
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
Clicking the warning opens the file Microsoft.NET.Sdk.DefaultItems.targets
at line 376. This file starts with a comment that says 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. *********************************************************************************************** -->
Line 376 falls in this XML element...
<Target Name="_CheckForUnnecessaryWindowsDesktopSDK" BeforeTargets="_CheckForInvalidConfigurationAndPlatform" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '5.0')) and '$(_MicrosoftWindowsDesktopSdkImported)' == 'true' and '$(TargetFrameworks)' == ''"> <NETSdkWarning ResourceName="UnnecessaryWindowsDesktopSDK" /> </Target>
There is a Project element that encloses the entire file. The element is this...
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> ...omissions... </Project>
Since that element does not mention Microsoft.NET.Sdk.WindowsDesktop SDK
the Project element does not seem to be the point at which the replacement Microsoft.NET.Sdk
should be placed.
How do I eliminate the cause of this warning?
Your project, the .csproj
file, not the MsBuild target xml. Change the top line to the following:
<Project Sdk="Microsoft.NET.Sdk">
This happens when you port the old project to .Net 5.
Perform a search of Project Sdk=
to open your .csproj
file, and correct the 1st line to <Project Sdk="Microsoft.NET.Sdk">
.
This should fix the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With