Browse Source

#3315: Ask for the WindowsDesktop SDK only where it is still needed

Microsoft.NET.Sdk imports the Windows Desktop targets itself for .NET
Framework and for .NET 5 and later, and warns (NETSDK1137) about every
project that still names the separate SDK. Only .NET Core 3.x, where
those targets are not imported without a platform-suffixed moniker,
genuinely needs Microsoft.NET.Sdk.WindowsDesktop.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
pull/4103/head
Siegfried Pammer 2 weeks ago
parent
commit
2900d18bca
  1. 14
      ICSharpCode.Decompiler.Tests/ProjectDecompiler/WpfProjectExportTests.cs
  2. 13
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs

14
ICSharpCode.Decompiler.Tests/ProjectDecompiler/WpfProjectExportTests.cs

@ -156,6 +156,20 @@ public sealed class WpfProjectExportTests @@ -156,6 +156,20 @@ public sealed class WpfProjectExportTests
}
}
/// <summary>
/// NETSDK1137: Microsoft.NET.Sdk carries the Windows Desktop targets itself since .NET 5, and
/// says so whenever a project still asks for the separate SDK.
/// </summary>
[TestCase(".NETCoreApp,Version=v10.0", "Microsoft.NET.Sdk")]
[TestCase(".NETFramework,Version=v4.7.2", "Microsoft.NET.Sdk")]
[TestCase(".NETCoreApp,Version=v3.1", "Microsoft.NET.Sdk.WindowsDesktop")]
public void WindowsDesktopSdkOnlyForNetCore3(string targetFramework, string expectedSdk)
{
string project = WriteProjectFile(WpfApplication(targetFramework, targetPlatform: null));
Assert.That(project, Does.Contain($@"<Project Sdk=""{expectedSdk}"">"));
}
/// <summary>
/// The markup compiler generates the program entry point into the application definition, so
/// the XAML file of the Application subclass is the one item that must not be a Page (#2253).

13
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs

@ -96,7 +96,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -96,7 +96,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
xml.WriteStartElement("Project");
var projectType = GetProjectType(module);
xml.WriteAttributeString("Sdk", GetSdkString(projectType));
xml.WriteAttributeString("Sdk", GetSdkString(projectType, TargetServices.DetectTargetFramework(module)));
using (new Group(xml, "PropertyGroup"))
{
@ -477,13 +477,20 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -477,13 +477,20 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
xml.WriteEndElement();
}
static string GetSdkString(ProjectType projectType)
static string GetSdkString(ProjectType projectType, TargetFramework targetFramework)
{
switch (projectType)
{
case ProjectType.WinForms:
case ProjectType.Wpf:
return "Microsoft.NET.Sdk.WindowsDesktop";
// Microsoft.NET.Sdk carries the Windows Desktop targets itself since .NET 5 and
// warns (NETSDK1137) about projects that still name the separate SDK; only
// .NET Core 3.x, where the desktop targets are not imported for a plain
// framework moniker, still needs it.
return targetFramework.Identifier == NetCoreAppIdentifier
&& targetFramework.VersionNumber >= 300 && targetFramework.VersionNumber < 500
? "Microsoft.NET.Sdk.WindowsDesktop"
: "Microsoft.NET.Sdk";
case ProjectType.Web:
return "Microsoft.NET.Sdk.Web";
default:

Loading…
Cancel
Save