How to Check .NET Core Versions

How to Check .NET Core Versions

.NET Core is an invaluable platform for developers. This open-source development platform, maintained by Microsoft, is used to build cloud-native apps, cross-platform apps, and even apps specifically for use on Internet of Things (IoT) devices. Problems can arise if a developer installs a newer version of .NET Core and then tries to run an older project. To prevent these problems, there are simple ways to check which .NET Core versions you have installed using the dotnet CLI (command-line interface).

Understanding .NET Core Versions

The earliest version of .NET Core dates back to 2016. It was created mainly to better support cross-platform app development. Since then, there have been 10 versions, with an eleventh projected for early November 2023 and a possible twelfth in late 2024. Currently, .NET is the naming convention, with the most recent version being .NET Core 3.1, which is still widely used by many app developers.

While backwards compatibility is a desirable quality in development tools, .NET Core has some limitations in this aspect. For example, if you install .NET Core version 3.1 and try to run a previous project created using an earlier version, you will encounter an SDK error. SDK stands for software development kit, and without the correct .NET Core SDK installed, you won’t be able to run your older projects.

The first step to overcome this issue is to use the dotnet CLI to discover the .NET Core versions you have installed.

Using the Command-Line Interface (CLI)

All installations of .NET Core SDK come with a command-line interface (CLI), allowing you to manually enter commands related to building, developing, and running your apps. If you’re unsure whether you have access to the dotnet CLI, follow these steps:

  • Open a command window by pressing the Windows key + R, typing “cmd”, and pressing enter
  • Type “dotnet” and press enter
  • You should see the following text:

Usage: dotnet [options]

Usage: dotnet [path-to-application]

Options:

   -h|–help         Display help.

   –info            Display .NET information.

   –list-sdks       Display the installed SDKs.

   –list-runtimes   Display the installed runtimes.

path-to-application:

   The path to an application .dll file to execute.

This indicates that you can use .NET Core commands in the CLI. All commands start with “dotnet” and are easy to remember.

To check the currently installed .NET Core SDK version, use this command:

dotnet –version

This will immediately show you the exact version of .NET Core you are currently running.

You can also use the command:

–list-sdks

To see which SDKs are installed and their locations on your machine.

Checking Multiple .NET Core Installations

Developers may have installed and utilized multiple versions of .NET Core and .NET. The previously mentioned command:

–list-sdks

shows exactly which versions of the .NET Core SDK are available. This should help developers understand why an SDK error may be occurring.

You can also use:

dotnet –list-runtimes

To show all installed runtime instances.

Note: You can find all currently installed SDK versions under the file path:

C:\Program Files\dotnet\sdk

This is unless you have manually chosen to install them elsewhere.

Understanding Project-based Version Checks

Understanding the current .NET Core versions only really helps if you know the version used to create the project you’re trying to run. There are a couple of ways to assess this. If you’re using an integrated development environment (IDE) like Visual Studio, you can access the .NET Core SDK version from the project settings.

It’s also possible to use a .csproj file for C# projects. This file acts like the DNA of the app you’re developing, holding key information on how .NET Core should build the app. This includes data on which instance of .NET Core SDK was used to create the project. You can use an “msbuild /bl” command on your .csproj file, which creates an msbuild.binlog file. You can open this file with a Microsoft Build Log Viewer to view all properties and values related to the project, including the NETCoreSdkVersion, which tells you the exact version used to create the project.

You can also check the target framework within the .csproj file, which states the version of the SDK your project is trying to use to run itself. What do you do if that version isn’t installed? Simple: Head to the .NET downloads page and ensure you have the correct version to run the relevant project.

Version control is critical in development, allowing for smarter and more efficient troubleshooting and a smoother shift towards a DevOps mentality within your organization. Understanding how to check which .NET Core version is associated with each project helps eliminate SDK errors and empowers you to dramatically reduce your time to market.