10

I am working on a .Net Framework 4.8 solution with 20-ish projects (among others WPF). We were discussing if we should convert our projects to SDK style now to get the new and improved project format.

Is the new SDK style the recommended approach for new .Net Framework projects? Or is it mostly used as a step on the way to converting to Core? I cannot find anything from Microsoft saying that you should do this and new projects in Visual Studio is still created using the old format. Is there any good reason NOT to convert to SDK style?

amgravem
  • 217
  • 1
  • 3
  • 9
  • (New versions of VS now at least push you a bit more towards the SDK-style csproj for all .NET Projects, but it's still not entirely clear) – canton7 Jun 22 '21 at 12:27
  • Yes. There's almost no reason to use the old-style csproj: SDK-style projects should be the default for all target frameworks, .NET Framework, .NET Core, .NET 5+, etc etc – canton7 Jun 22 '21 at 12:35
  • @canton7 How do you mean they push you towards using the SDK-style? I cannot find there is an option using the SDK style at in VS2022 Preview when creating a .Net Framework Class Lib. – amgravem Jun 24 '21 at 17:10
  • That's the point: it's no longer called out especially (you used to only get an SDK-style csproj if you opted for a ".NET Core project") – canton7 Jun 24 '21 at 19:54

1 Answers1

6

For starting a new project, you could use the new SDK style (common project system).It is suitable for most project types, but not all project types.

We can know from here that the Default project format of .NET Framework is Non-SDK-style, .NET Core and .NET Standard are SDK-style.

I think if it is not necessary, the .NET Framework may not use the SDK style for the time being. For creating an sdk style .net framework project. We need to set it manually.

For example, you could create a Class Library (.NET Standard) project and modify the csproj file.

The initial file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>

You can edit it to:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
     <TargetFramework>net48</TargetFramework>
  </PropertyGroup>
</Project>

Then, you could get a sdk-style .net framework project.

enter image description here

SDK-style is a project format and may not be related to the conversion of .NET Framework to .NET Core.

You can migrate the old .NET Framework projects to .NET Core projects if needed. For porting projects, you could refer to Considerations when porting and Windows desktop technologies.

Hui Liu-MSFT
  • 770
  • 4
  • 15
  • 1
    Note that recent versions of VS now prompt you to select the target framework when creating a new SDK-style csproj, and it's no longer called a ".NET Core project" – canton7 Jun 24 '21 at 19:55
  • @canton7 Which versions of VS are you talking about? I'm on both latest VS2019 Pro and VS2022 Preview and they both have the traditional projects. Either Class Library (.Net Framework) or Class Library (targeting standard and Core). There is no automatic in getting a SDK style project for .Net Framework here as far as I can see. – amgravem Jun 25 '21 at 06:56
  • @hui-liu-mfst Thank you for the detailed answer! I understand there is no absolute answer for everyone. The link to the default projects does indeed point to using the old version for now. – amgravem Jun 25 '21 at 06:59
  • @amgravem Right, but it's now called "Class Library" rather than ".NET Core Class Library" (or whatever the old name was) – canton7 Jun 25 '21 at 07:41
  • 2
    Can we have both classic csproj and sdk-style csproj files in the same solution? – scuba88 Mar 11 '22 at 19:39
  • 1
    @scuba88 Yes you can mix project styles in a solution, we have changed almost all projects over, except for ASP.NET sites, this works without issues. – NiKiZe May 26 '22 at 07:54
  • can you target .netframework with sdk-style to author an winforms library? it seems to me that it is not possibile. – spartaco Jan 10 '23 at 09:42
  • @spartaco May have to convert to SDK-style after project creation. I converted my WPF project OK. See my answer here: https://stackoverflow.com/a/75316507/623561 – Wes Feb 01 '23 at 21:49