Florian Hilfenhaus
Florian Hilfenhaus

Reputation: 102

Is .NET Core Sdk backwards compatible with previous releases?

I am a bit confused. I found this question which is for the runtime. It also targets the SDK and says:

  1. Edit .NET Core 3.x SDK has been released. Unlike v2.2 and the previous releases before it, this version does not support the ability to target previous runtimes (i.e. netcoreapp2.2, netcoreapp2.1, etc)

  2. That means, you do not need to install more than one SDK on your build server if you want to build against multiple runtimes (even though you could).

But I can use the global.js with dotnet sdk 6 to target a dotnetcore 3 app.

For me it looks like I only need the latest SDK to build all the previous, right?

If so, how is that accomplished, will every new SDK contains all the others? Or how ms (I heard Java works the same) accomplish the backward compatibility?

Upvotes: 3

Views: 2697

Answers (1)

omajid
omajid

Reputation: 15203

There's a few different things in play here.

global.json lets you select which SDK to use. Not which one (runtime) to target, but which SDK to use, if you have more than one SDK installed.

To select which runtime to target, use the TargetFramework element in your .csproj file. For example, <TargetFramework>netcoreapp3.1</TargetFramework>

Recent versions of the SDK let you target older runtimes. A 6.0 SDK will let you target the 3.1 runtime without any issues.

Still, multiple versions of the SDK might generate different code or do things differently enough that breaks your application. Using a matching SDK and Runtime is probably the safest bet.

If you are in the middle of development (eg, dotnet build) or have built a Framework Dependent Application (an application that's not self contained and needs a .NET Runtime to work), you will need to install the matching runtime to run the application. A new SDK doesn't have the older runtime.

For all other (self-contained) applications, all versions of the the Runtime (current and old versions) are available as nuget packages. The SDK pulls them down and uses them when building your application.

Upvotes: 3

Related Questions