Using Multiple .Net Core Versions on Unbuntu 19.04

7 months ago

It's possible to install an use multiple versions of .Net Core on a Linux system.  This is convenient if you want to try out upcoming preview versions but still keep the current stable, or in the scenario where there is an occasional need for using an earlier version of the

It's possible to install an use multiple versions of .Net Core on a Linux system.  This is convenient if you want to try out upcoming preview versions but still keep the current stable, or in the scenario where there is an occasional need for using an earlier version of the framework?

So how to we do this?  First, install using the binary SDK downloads instead of snap or apt-get.  This gives the flexibilty to put the SDK in a parallel directory to other framework versions.  Taking a look at my system I currently have two versions in my home folder, each in a folder with a name representing the framework version:

mike@threadripper:~$ ls -ld  dotnet*
drwxr-xr-x 7 mike mike 4096 May 16  2018 dotnet-2.1
drwxr-xr-x 5 mike mike 4096 Mar 22 14:24 dotnet-2.2-203

How do I select between them?  Let's examine...  

Everything in .Net Core revolves around using the dotnet command. Let's see what  happens when you run the dotnet command.

mike@threadripper:~$ which dotnet
/home/mike/.bin/dotnet
mike@threadripper:~$ ls -l $(which dotnet)
lrwxrwxrwx 1 root root 32 Apr 30 12:29 /home/mike/.bin/dotnet -> /home/mike/dotnet-2.2-203/dotnet
mike@threadripper:~$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.203
 Commit:    e5bab63eca

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  19.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/mike/dotnet-2.2-203/sdk/2.2.203/

Host (useful for support):
  Version: 2.2.4
  Commit:  f95848e524

.NET Core SDKs installed:
  2.2.203 [/home/mike/dotnet-2.2-203/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.4 [/home/mike/dotnet-2.2-203/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.4 [/home/mike/dotnet-2.2-203/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.4 [/home/mike/dotnet-2.2-203/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

which dotnet shows what is executed when dotnet is run.  In this case, it runs the dotnet command in my /home/mike/.bin folder.  That's because I have that folder in my path.  But, as can be seen, this is actually a symbolic link to the dotnet executable in the /home/mike/dotnet-2.2-203 folder, and hence wil utilize the 2.2.203 version of the framework.

mike@threadripper:~$ ls -l $(which dotnet)
lrwxrwxrwx 1 root root 32 Apr 30 12:29 /home/mike/.bin/dotnet -> /home/mike/dotnet-2.2-203/dotnet

To change to another version, I create a bash shell file for each desired version.  As an example, this one,set-dotnet-2.1.sh, also located in /home/mike/.bin changes the symbolic link to point to the ~/dotnet-2.1/dotnet executable.

mike@threadripper:~$ cat ~/.bin/set-dotnet-2.1.sh
rm -f ~/.bin/dotnet
ln -s ~/dotnet-2.1/dotnet ~/.bin/dotnet
mike@threadripper:~$ sudo set-dotnet-2.1.sh
mike@threadripper:~$ dotnet --info
.NET Command Line Tools (2.1.201)

Product Information:
 Version:            2.1.201
 Commit SHA-1 hash:  7932dc6179

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  19.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/mike/dotnet-2.1/sdk/2.1.201/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.7
  Build    : 2d61d0b043915bc948ebf98836fefe9ba942be11

And to get back to 2.2 I have the following:

mike@threadripper:~$ cat ~/.bin/set-dotnet-2.2.sh
rm -f ~/.bin/dotnet
ln -s ~/dotnet-2.2-203/dotnet ~/.bin/dotnet
mike@threadripper:~$ sudo set-dotnet-2.2.sh
mike@threadripper:~$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.203
 Commit:    e5bab63eca

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  19.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/mike/dotnet-2.2-203/sdk/2.2.203/

Host (useful for support):
  Version: 2.2.4
  Commit:  f95848e524

.NET Core SDKs installed:
  2.2.203 [/home/mike/dotnet-2.2-203/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.4 [/home/mike/dotnet-2.2-203/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.4 [/home/mike/dotnet-2.2-203/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.4 [/home/mike/dotnet-2.2-203/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Comments