/ 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:
#!/bin/bash

function sdk_help(){
echo ".NET Command Line SDK Switcher (1.0.0)
Usage: dotnet sdk [command]
Usage: dotnet sdk [version]
Commands:
  latest      Swtiches to the latest .NET Core SDK version
  list        Lists all installed .NET Core SDKs
  help        Display help
Versions:
  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
	fi
	
	echo ".NET Core SDK version switched to latest version."
	dotnet --version
}

case "$1" in 
	"help")
		sdk_help
		;;
	"")
		sdk_help
		;;
	"list")
		sdk_list
		;;
	"latest")
		sdk_latest
		;;
	*)
		echo "Switching .NET Core SDK version to $1"
		echo "{
  \"sdk\": {
    \"version\": \"$1\"
  }
}" >> global.json
		;;
esac
  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:
1.0.4
2.0.0-preview2-006497

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:

export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

Bounce

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:

export DOTNET_CLI_TELEMETRY_OPTOUT=1

Good luck.