How to use the latest target framework available for a .NET SDK

 
 
  • Gérald Barré

Sometimes, you don't want to bother with the target framework version of your project. You just want to use the latest version available from the .NET SDK. This can be useful if you want to always be on the latest version and don't want to spend time updating the .csproj files. You can fix the version of the SDK in a global.json file and use tools such as Renovate to update the version of the SDK for you.

Create a global.json file at the root of your project to fix the version of the SDK.

Shell
dotnet new globaljson

Then, update the .csproj to set the target framework to the latest version available for the SDK.

MyProject.csproj (csproj (MSBuild project file))
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net$(NETCoreAppMaximumVersion)</TargetFramework>
  </PropertyGroup>
</Project>

That's it! You can now use the latest target framework available for your .NET SDK.

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub