41

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?

H2ONaCl
  • 10,644
  • 14
  • 70
  • 114
  • [NETSDK1137: Don't use the Microsoft.NET.Sdk.WindowsDesktop SDK](https://learn.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1137) – Jackdaw Oct 01 '22 at 12:22

2 Answers2

78

Your project, the .csproj file, not the MsBuild target xml. Change the top line to the following:

<Project Sdk="Microsoft.NET.Sdk">
Blindy
  • 65,249
  • 10
  • 91
  • 131
15

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.

bguiz
  • 27,371
  • 47
  • 154
  • 243
Formless
  • 157
  • 1
  • 3