How to install multiple ASP.NET Core Runtimes in MacOS
I had this issue the other day after upgrading to the latest .NET 5 SDK, and banged my head against it for a while. There is sparse documentation on how to do this end-to-end, so here goes!
Why you would need to do this
After upgrading my SDK to .NET 5 (via brew
on the CLI), I found I had no .NET or ASP.NET 3.1 runtimes anymore. This meant that when trying to open existing netcoreapp3.1
applications on my machine i was greeted with a lovely message:
The link sends you to a page where there is no MacOS runtime available for ASP.NET Core 3.1.
The solution — install it yourself.
Let’s do it
Head here: https://dotnet.microsoft.com/download/dotnet-core/3.1
On the right you’ll find this table.
For MacOS, installing the .NET Core runtime is easy, there’s an installer for it. However, the ASP.NET Core runtime not so much. If you download the binaries, they come with no instructions, and don’t seem to include everything you need anyway.
We can avoid both the installer and the binaries with the final option in the list. In the All
OS option right at the bottom for .NET Core Runtime, download the dotnet-install scripts
.
Pick the shell version, which will work on your Mac.
Getting your runtime directories
Now run this:
dotnet --list-runtimes
This will show you where you current runtimes are installed. In my case they’re here and show the existing 5.0.2
ones in /usr/local/share/dotnet
:
Microsoft.AspNetCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Getting the ones you want installed
Once you’ve got it, swing by your downloads folder in your terminal and run:
chmod +x dotnet-install.shsudo ./dotnet-install.sh --runtime dotnet --version 3.1.12 --install-dir /usr/local/share/dotnetsudo ./dotnet-install.sh --runtime aspnetcore --version 3.1.12 --install-dir /usr/local/share/dotnet
The dotnet-install.sh
will download your runtimes, and install them in /usr/local/share/dotnet
.
dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.dotnet-install: ASP.NET Core Runtime version 3.1.12 is already installed.
dotnet-install: Adding to current process PATH: `/usr/local/share/dotnet`. Note: This change will be visible only when sourcing script.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://docs.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
dotnet-install: Installation finished successfully.
Now re-run dotnet --list-runtimes
and behold!
Microsoft.AspNetCore.App 3.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
We have our 3.1.12 runtimes 🎉
Try running your netcoreapp3.1
again:
Conclusion
This should work for any runtime version you require, not just 3.1.12
. Just change the version passed in when you call dotnet-install.sh
.
If you want to install in a different directory for dotnet, just make sure you set the --install-dir
to the dotnet
directory where your installation lives, not the dotnet/shared
directory.