/ ASP.NET Core

Switching between .NET SDK versions on macOS

As a developer, you always wish to experiment with the latest versions, sometimes even when they still in pre-release stage.

I downloaded the latest .NET Core (2.0.0-preview2-006497) to check what is new and what is changing. All fine until one I wanted to swish to the stable release for some work.

Here I found this script (here)[https://github.com/faniereynders/dotnet-sdk-helpers] which will help you switch between your .NET SDK versions.

How to install it.

  1. Open a terminal window and type cd ~
  2. Create a new file called dotnet-sdk using the command touch dotnet-sdk
  3. Edit the file nano dotnet-sdk
  4. Paste the following code:

function sdk_help(){
echo ".NET Command Line SDK Switcher (1.0.0)
Usage: dotnet sdk [command]
Usage: dotnet sdk [version]
  latest      Swtiches to the latest .NET Core SDK version
  list        Lists all installed .NET Core SDKs
  help        Display help
  An installed version number of a .NET Core SDK"

function sdk_list(){
	echo "The installed .NET Core SDKs are:"
	ls -1 "/usr/local/share/dotnet/sdk"

function sdk_latest(){
	if [ -e global.json ]; then
		rm global.json
	echo ".NET Core SDK version switched to latest version."
	dotnet --version

case "$1" in 
		echo "Switching .NET Core SDK version to $1"
		echo "{
  \"sdk\": {
    \"version\": \"$1\"
}" >> global.json
  1. Make your dotnet-sdk file executable using the command chmod +x dotnet-sdk
  2. Create a symbolic link to it in /usr/local/bin using the command ln -s ~/dotnet-sdk /usr/local/bin/

Thats it.

To list the installed versions on your machine execute dotnet sdk list, you will get something like:

The installed .NET Core SDKs are:

To switch to 1.0.4 dotnet sdk 1.0.4 and to get back to 2.0.0 dotnet sdk 2.0.0-preview2-006497.

If you received an error like this: Failed to create prime the NuGet cache. new failed with: XXX try to run this command:



The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include command-line arguments. The data is collected by Microsoft and shared with the community. To stop this, execute this command:


Good luck.