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

 
 
  • Gérald Barré

Sometimes you want to avoid tracking the target framework version across your projects and simply use whatever the installed .NET SDK supports. This is useful when you want to stay on the latest version without manually updating every .csproj file. You can pin the SDK version in a global.json file and use a tool like Renovate to keep it up to date automatically.

Create a global.json file at the root of your repository to pin the SDK version.

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?