Close

.Net Core

Based on PluralSight session:
What you need to know about .Net Core
Kathleen Dollard, DEVintersection, Dec 2019.

Introduction

.Net Core is:
– Cross-platfom (runs on Windows, Mac, Linux)
– Open Source
– Multi-Language (C#, VB, F#)

The .Net Framework runtime is not cross-platform, but linked to Windows. It’s always one copy at one fixed place on your computer. Of .Net Core we can install multiple versions. These versions can be used side by side, but by default the latest version is used.

This is what you get when you download the SDK:

It’s very important to distinguish among the .Net Core RunTime and the .Net Core SDK. Also know that Roslyn provides open-source C# and Visual Basic compilers with rich code analysis APIs. Roslyn is a built-in feature of Visual Studio and enables building code analysis tools.

To check latest .Net Core version used:
Start/Run cmd
dotnet –version
To see all .Net Core versions installed:
dotnet –list-sdks

If we go to the command line or PowerShell, we can for instance run the following commands to create a simple “Hello World” .Net Core Console App:
cd, dir for contents
dotnet new console -o session (=outputdir)
code . (Opens visual studio code)

When we look at the created console app, we see a very simple project file where we can set the target framework to the correct .Net Core version. Here we actually specify the .Net Core Runtime version, not the .Net Core SDK version. As we will see later on, you can change the project file as a developer. That’s different from .Net Framework where the project file was purely designed for the machine.

When you run the .Net Core App, the runtime simply looks for all the .cs files and executes those. A build and restore will be performed automatically.
cd session
dotnet run

After developing and testing your application, you can do a build and publish.

Support Policy

.Net Framework is part of Windows and is automatically updated as part of the Windows updates. It follows the Windows support policy. Windows currently supports .Net Framework 4.8.

.Net Core has a different timeline and support policy. It’s independent from Windows, meaning that it’s easier to make fixes and be earlier on schedule.
Distinguish among:

  • Long Term Support releases (LTS). Support 3 years from release or 1 year after next LTS release
  • Current. Support until 3 months after next release.

If a new version of .Net Core is released, that doesn’t mean the old version no longer works. It means the old version is no longer fixed. That’s why you are always requested to update to the latest release, in case you run into problems. Microsoft recommends to be on the current(=latest) version, unless you really need that long-term support.

Also: Each SDK builds apps for earlier runtimes. So you can take the 3.0 runtime and build for 2 1. Breaking changes are minimized and you will only have a few things to fix.

Starting from version 5.0 (nov 2020) .Net Core will be relabeled to simply .Net, because .Net Core is the way Microsoft moves forward. At the same time, .Net Framework as part of Windows will probably be supported for like 20 years.

SDK Versioning

Version numbers follow the major.minor.patch notation, but it’s not true semantic versioning.

  • Major and minor numbers are for the .Net Core Runtime.
  • Patch is for the .Net Core SDK.

A distiction is made between major/minor and patch, because the SDK goes much faster than the Runtime. The runtime must be solid as a rock.

Nowadays, SDK Versioning is just nuts. Don’t try to understand it. Microsoft tries to improve on this.

An important notion for the new versioning strategy is: Pulling the SDK and Runtime version apart. There will no longer be a separate SDK for every supported Runtime. So, if you are within Visual Studio, you will still get runtime patches, but the SDK will just keep running on those patches.

Zie: dotnet.microsoft.com/download
On Download page you can see which version of Visual Studio it’s for.

SDK Selection

The .Net Core SDK version is selected via the Bootstrapper. Bootstrapper takes the latest .Net Core version installed on the machine by default. It’s very important to realize there’s only one bootstrapper on your machine. If you uninstall a version of the .Net Core SDK, the bootstrapper is left behind.

Global.json forces a different SDK selection or SDK Pinning as we call it.

It really matters where you put global.json. The first one found in the file hierarchy is used. So we recommend solution or even repository root. Global.json doesn’t only allow you to select the .Net Core version, it also allows you to specify AllowPreRelase and RollForward.

If you specify AllowPreRelease=false, that means you don’t want to use previews. If you disable RollForward, you say: give me that one exact version.

RollForward is especially relevant when you work on a project with multiple people:
– If a person is below your .Net Core version, you set a baseline in global.json to use for instance 3.1 as a minimum.
– If a person is on a higher version, it’s very likely they wanna use their latest tools. In this case, simply don’t specify anything in global.json.
– If you are afraid of breaking code changes, use the global.json file and RollForward.

You can set RollForward to:
– Patch, feature, minor or major to get the closest match within the specific limit.
– LatestPatch, LatestFeature, LatestMinor or LatestMajor to allow for the highest or latest patch/feature/minor/major version.

Note: there’s a typo in the above screenprint. “Anything above major” must be “Anything above minor”. That’s because you limit by feature.

Runtime Selection

You can also enter in the project file (not global.json). This is for the runtime version only. Not for the entire SDK. Let’s say you build an application on version 2.2. If you don’t know the .Net Core version of the machine you are running on. Forward can make it possible to use any new version. If you run the code, you can see 3.0 is used, but it can be any version from 3.0 onwards.

<TargetFramework>2.2</TargetFramework>
<RuntimeFrameworkVersion>2.2.0</RuntimeFrameworkVersion>
<RollForward>LatestMajor</RollForward>

Visual Studio

If you are in VS2019 and want to build a .Net Core 3.* app, you will have to do nothing. You need an old version of VS to build for 2.0 or 2.1.

Uitzoeken:
Je hebt VS 2019 geinstalleerd. Kun je dan onderhoud plegen op een 2.0 of 2.1 applicatie?
Je hebt VS 2017 geinstalleerd. Kun je dan een 3.0 applicatie bouwen?
Hoe selecteert Visual Studio de .Net Core version? Niet via Bootstrapper denk ik.