Managing your .NET Core SDK versions with the .NET Install SDK Global Tool
Posted on Tuesday, 03 Sep 2019
During my day to day programming activities I regularly find myself switching between various .NET Core solutions. At work we have a multitude of .NET Core microservices/microsites and at home I enjoy contributing to OSS projects/reading other people's code. As I'm switching between these solutions I regularly come across a project that uses a
global.json file to define the version of the .NET Core SDK required.
What is the global.json file?
For those that might not be familiar the global.json file, here's an excerpt from the docs:
The global.json file allows you to define which .NET Core SDK version is used when you run .NET Core CLI commands. Selecting the .NET Core SDK is independent from specifying the runtime your project targets. The .NET Core SDK version indicates which versions of the .NET Core CLI tools are used. In general, you want to use the latest version of the tools, so no global.json file is needed.
You can read more about it here, so let's continue.
Upon stumbling on a project with a global.json file I'd go through the manual process of locating the correct version of the SDK to download then installing it. After a number of times doing this, as most developers would, I decided to remove the friction by creating a .NET Core global tool to automate this process.
Note: Before I continue, a huge thanks to Stuart Lang who was running into the same frustrations, noticed I'd started this tool and contributed a tonne towards it.
.NET Core Install SDK Global Tool
If you want to give it a try you can install the global tool on your machine by running the following command (assuming you've got .NET Core installed).
$ dotnet tool install -g installsdkglobaltool
Once installed the global tool has the following features:
Install .NET Core SDK based on global.json file
If you navigate to a folder with a
global.json file in it and run the following command:
$ dotnet install-sdk
The global tool will check the contents of the
global.json file and download then start the installation of the defined version of the .NET Core SDK.
Install the latest preview of the .NET Core SDK
It's always fun playing with the latest preview releases of the .NET Core SDK so to save you time finding the latest version you can simply run:
$ dotnet install-sdk --latest-preview
This will download and start the installation of the latest preview version of the .NET Core SDK.
Is this suitable for build/CI environments?
No, certainly not at this moment in time. This global tool has been built with a consumer focus so does not install the SDK in a headless fashion. Instead it launches the install and still gives you the same control you're used to (such as choosing install location).
If you're interested in what the whole experience looks like then check out the video below:
Until next time!