.NET is 20 years old this week and I’ve been using it for a big chunk of that. It’s come a long way since the early days when I started and is now cross-platform.
.NET Core 3.1 LTS support ends on the 3rd of December this year (2022) and .NET 5.0 on the 8th of May this year. .NET 6.0 LTS is supported until the 8th of November 2024 so you will need to update to this in order to continue getting security patches.
You may also want to update the version of C# in use to take advantage of new features and this is a good time to do it. Here is how I updated my Huxley 2 railway data proxy from .NET Core 3.1 LTS to .NET 6.0 LTS (including for the Docker container and Azure pipelines support) and from C# 8 to C# 10.
You will need to edit your
.csproj project files to upgrade the framework and language. If you use Docker or Azure Pipelines then you will need to update the configuration files for these too.
Make sure that you have the latest version of the .NET SDK installed. You can download it from dotnet.microsoft.com.
.csproj XML files. Change the
TargetFramework tag content from e.g.
net6.0 so that it looks like this:
<PropertyGroup> <TargetFramework>net6.0</TargetFramework> </PropertyGroup>
Other tags have been omitted for clarity. Don’t forget to do this for all of your project files, including unit test projects.
You may also want to update the C# version to use new language features. Change the
LangVersion tag content from e.g.
10.0 so that it looks like this:
<PropertyGroup> <TargetFramework>net6.0</TargetFramework> <LangVersion>10.0</LangVersion> </PropertyGroup>
Save the files, rebuild everything, run all the automated tests and give it a good manual test to make sure everything is working.
If you use Docker then you will need to update your
Dockerfile to use the latest images. If you are using ASP.NET Core then change e.g.
mcr.microsoft.com/dotnet/sdk:6.0 for the SDK and e.g.
mcr.microsoft.com/dotnet/aspnet:6.0 for the runtime so that it looks like this:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env FROM mcr.microsoft.com/dotnet/aspnet:6.0
Other lines have been omitted for clarity. Note the removal of
core from the path.
If you use YAML Azure Pipelines then you will need to update the
azure-pipelines.yml file. Change the first task to install the latest patch version of the .NET 6.0 SDK by changing
6.0.x so that it looks like this:
stages: - stage: Build_and_test_stage jobs: - job: Build_and_test_job pool: vmImage: 'ubuntu-latest' steps: - task: UseDotNet@2 displayName: "Use .NET 6.0 SDK" env: DOTNET_CLI_TELEMETRY_OPTOUT: true DOTNET_NOLOGO: true inputs: packageType: 'sdk' version: '6.0.x'
The build, test and publish tasks etc. shouldn’t need any changes but the final deploy task will if you are hosting on the Azure web app service. Change
DOTNETCORE|6.0 so that it looks like this:
- task: AzureRmWebAppDeployment@4 displayName: 'Deploy Huxley 2 to Azure web app service' inputs: RuntimeStack: 'DOTNETCORE|6.0'
Again, other lines have been omitted for clarity.
GitHub Actions is similar (it shares a lot with Azure Pipelines) but it is a little different. Have a look at the
dotnet-version: 6.0.x line in the Huxley 2 CI config.
Happy upgrades and happy birthday .NET!