-->
- The Command 'dotnet' Is Not Recognized As The Name Of A Cmlet ..
- How To Open Applications Using Terminal On Mac: 12 Steps
Docker-ing your life Since we don't currently have the Microsoft SQL Server engine available for MacOS, I had to use Docker in order to install Linux's MS SQL Server in a container and although this may sound complicated at first, there's a really awesome post written by @reverentgeek that can teach you exactly how to do it and even more! I've created a.NET Core console application. I want to build the app so that I can execute it on Windows or MacOS without dotnet core being installed on the machine.
In this article, you'll learn how to install .NET on macOS. .NET is made up of the runtime and the SDK. The runtime is used to run a .NET app and may or may not be included with the app. The SDK is used to create .NET apps and libraries. The .NET runtime is always installed with the SDK.
The latest version of .NET is 5.0.
Supported releases
The following table is a list of currently supported .NET releases and the versions of macOS they're supported on. These versions remain supported either the version of .NET reaches end-of-support.
- A ✔️ indicates that the version of .NET Core is still supported.
- A ❌ indicates that the version of .NET Core isn't supported.
Operating System | .NET Core 2.1 | .NET Core 3.1 | .NET 5.0 |
---|---|---|---|
macOS 10.15 'Catalina' | ✔️ 2.1 (Release notes) | ✔️ 3.1 (Release notes) | ✔️ 5.0 (Release notes) |
macOS 10.14 'Mojave' | ✔️ 2.1 (Release notes) | ✔️ 3.1 (Release notes) | ✔️ 5.0 (Release notes) |
macOS 10.13 'High Sierra' | ✔️ 2.1 (Release notes) | ✔️ 3.1 (Release notes) | ✔️ 5.0 (Release notes) |
macOS 10.12 'Sierra' | ✔️ 2.1 (Release notes) | ❌ 3.1 (Release notes) | ❌ 5.0 (Release notes) |
Unsupported releases
The following versions of .NET are ❌ no longer supported. The downloads for these still remain published:
- 3.0 (Release notes)
- 2.2 (Release notes)
- 2.0 (Release notes)
Runtime information
The runtime is used to run apps created with .NET. When an app author publishes an app, they can include the runtime with their app. If they don't include the runtime, it's up to the user to install the runtime.
There are three different runtimes you can install on macOS:
ASP.NET Core runtime
Runs ASP.NET Core apps. Includes the .NET runtime.
Runs ASP.NET Core apps. Includes the .NET runtime.
.NET runtime
This runtime is the simplest runtime and doesn't include any other runtime. It's highly recommended that you install ASP.NET Core runtime for the best compatibility with .NET apps.
This runtime is the simplest runtime and doesn't include any other runtime. It's highly recommended that you install ASP.NET Core runtime for the best compatibility with .NET apps.
SDK information
The SDK is used to build and publish .NET apps and libraries. Installing the SDK includes both runtimes: ASP.NET Core and .NET.
Dependencies
.NET is supported on the following macOS releases:
The Command 'dotnet' Is Not Recognized As The Name Of A Cmlet ..
.NET Core Version | macOS | Architectures | More information |
---|---|---|---|
5.0 | High Sierra (10.13+) | x64 | More information |
3.1 | High Sierra (10.13+) | x64 | More information |
3.0 | High Sierra (10.13+) | x64 | More information |
2.2 | Sierra (10.12+) | x64 | More information |
2.1 | Sierra (10.12+) | x64 | More information |
Beginning with macOS Catalina (version 10.15), all software built after June 1, 2019 that is distributed with Developer ID, must be notarized. This requirement applies to the .NET runtime, .NET SDK, and software created with .NET.
The runtime and SDK installers for .NET 5.0 and .NET Core 3.1, 3.0, and 2.1, have been notarized since February 18, 2020. Prior released versions aren't notarized. If you run a non-notarized app, you'll see an error similar to the following image:
For more information about how enforced-notarization affects .NET (and your .NET apps), see Working with macOS Catalina Notarization.
libgdiplus
.NET applications that use the System.Drawing.Common assembly require libgdiplus to be installed.
An easy way to obtain libgdiplus is by using the Homebrew ('brew') package manager for macOS. After installing brew, install libgdiplus by executing the following commands at a Terminal (command) prompt:
Install with an installer
macOS has standalone installers that can be used to install the .NET 5.0 SDK:
Download and manually install
As an alternative to the macOS installers for .NET, you can download and manually install the SDK and runtime. Manual install is usually performed as part of continuous integration testing. For a developer or user, it's generally better to use an installer.
If you install .NET SDK, you don't need to install the corresponding runtime. First, download a binary release for either the SDK or the runtime from one of the following sites:
- ✔️ .NET 5.0 downloads
- ✔️ .NET Core 3.1 downloads
- ✔️ .NET Core 2.1 downloads
Next, extract the downloaded file and use the
export
command to set variables used by .NET and then ensure .NET is in PATH.To extract the runtime and make the .NET CLI commands available at the terminal, first download a .NET binary release. Then, open a terminal and run the following commands from the directory where the file was saved. The archive file name may be different depending on what you downloaded.
Use the following command to extract the runtime:
Use the following command to extract the SDK:
Tip
The preceding
export
commands only make the .NET CLI commands available for the terminal session in which it was run.You can edit your shell profile to permanently add the commands. There are a number of different shells available for Linux and each has a different profile. For example:
- Bash Shell: ~/.bash_profile, ~/.bashrc
- Korn Shell: ~/.kshrc or .profile
- Z Shell: ~/.zshrc or .zprofile
Edit the appropriate source file for your shell and add
:$HOME/dotnet
to the end of the existing PATH
statement. If no PATH
statement is included, add a new line with export PATH=$PATH:$HOME/dotnet
.Also, add
export DOTNET_ROOT=$HOME/dotnet
to the end of the file.This approach lets you install different versions into separate locations and choose explicitly which one to use by which application.
Install with Visual Studio for Mac
How to block mac apps to stay focused. Visual Studio for Mac installs the .NET SDK when the .NET workload is selected. To get started with .NET development on macOS, see Install Visual Studio 2019 for Mac.
.NET SDK version | Visual Studio version |
---|---|
5.0 | Visual Studio 2019 for Mac version 8.8 or higher. |
3.1 | Visual Studio 2019 for Mac version 8.4 or higher. |
2.1 | Visual Studio 2019 for Mac version 8.0 or higher. |
Install alongside Visual Studio Code
Visual Studio Code is a powerful and lightweight source code editor that runs on your desktop. Visual Studio Code is available for Windows, macOS, and Linux.
While Visual Studio Code doesn't come with an automated .NET installer like Visual Studio does, adding .NET support is simple.
How To Open Applications Using Terminal On Mac: 12 Steps
- Download and install Visual Studio Code.
- Download and install the .NET SDK.
- Install the C# extension from the Visual Studio Code marketplace.
Install with bash automation
The dotnet-install scripts are used for automation and non-admin installs of the runtime. https://evermilliondollar919.weebly.com/blog/delete-apps-from-menu-bar-on-mac. You can download the script from the dotnet-install script reference page.
The script defaults to installing the latest long term support (LTS) version, which is .NET 3.1. You can choose a specific release by specifying the
current
switch. Include the runtime
switch to install a runtime. Otherwise, the script installs the SDK.Note
The previous command installs the ASP.NET Core runtime for maximum compatability. The ASP.NET Core runtime also includes the standard .NET runtime.
Docker
Containers provide a lightweight way to isolate your application from the rest of the host system. Containers on the same machine share just the kernel and use resources given to your application.
.NET can run in a Docker container. Official .NET Docker images are published to the Microsoft Container Registry (MCR) and are discoverable at the Microsoft .NET Core Docker Hub repository. Each repository contains images for different combinations of the .NET (SDK or Runtime) and OS that you can use.
Microsoft provides images that are tailored for specific scenarios. For example, the ASP.NET Core repository provides images that are built for running ASP.NET Core apps in production.
For more information about using .NET Core in a Docker container, see Introduction to .NET and Docker and Samples.
Next steps
- How to check if .NET Core is already installed.
- Working with macOS Catalina notarization.
- Tutorial: Get started on macOS.
- Tutorial: Create a new app with Visual Studio Code.
- Tutorial: Containerize a .NET Core app.
Astute observers will note that .NET Core has been out for quite some time now, with no “GUI” option of building applications. This seems rather deliberate, with Microsoft instead intending to focus on web applications instead of desktop apps. This is also coupled with the fact that to create a cross platform GUI library is easier said then done. Creating something that looks good on Windows, Mac and Linux is no easy feat.
And that’s where Eto.Forms jumps in. It’s a GUI library that uses the native toolkit of each OS/Platform through a simple C# API. Depending on where it is run, it will use WPF, MonoMac or GTK#. It isn’t necessarily using .NET Core (Infact it definitely isn’t, it uses Mono on non Windows platforms), but because one of the main reasons to switch to Core is it’s ability to be cross platform and work on non-windows OS, I thought I would have a little play with it.
In this first post, we will just be working out how to do a simple test application. In future posts, we will work out how to run platform specific code and how better to deploy our application that doesn’t involve a tonne of dependencies to be installed on the machine (For example bundling mono with your application). I’ve spent quite a bit tinkering with this and so far, definitely so good.
Setup Within Visual Studio
When using Visual Studio, we want to take advantage of code templates so that our “base” solution is created for us.
Inside Visual Studio, go to Tools -> Extensions and Updates. Hit “Online” on the left hand side, then type in “Eto.Forms” in your search box.
Go ahead and install the Eto.Forms Visual Studio Addin. It’s highly likely after install you will also need to restart Visual Studio to complete the installation.
When you are back in Visual Studio, go ahead and create a new project. You should now have a new option to create an “ETO Forms Project”.
After selecting this, you are going to be given a few options on the project. The first is that do you want all 3 platforms to be within a single application, or a separate application for each. For the purpose of this demo we are going to go ahead and do 3 separate projects. The only reason we do this is so that building becomes easier to “see” because you have a different bin folder for each platform. As a single project, everything gets built into the same bin folder so it just looks a bit overwhelming.
Next you are given options on how you want to define your layout. And here’s where you might tune out. If you are expecting some sort of WYSIWYG designer, it ain’t happening. You can define everything with C# code (Sort of like how Winforms would generate a tonne of code in the background for you), you can use XAML, or you can use JSON. Me personally, I’m a WinForm kinda guy so I prefer defining the forms in C# code. So I’m going to go ahead and use that in this example. I can definitely see in the future someone building a tool ontop that simply generates the underlying code, but for now, you’ll have to live with designing by hand.
Now we should be left with 4 projects. The first being our “base” project. This defines the forms and shared code no matter which platform we actually end up running on. The other 3 projects are for Linux, Mac and Windows respectively. As I said earlier, if we select the option to have a “single” project, we actually end up with two projects. One that contains shared code, and one that actually launches the thing (But builds for all 3 platforms).
In each of these .csproj files, you will find a line like :
Which basically tells it which platform to build for. And again, you can combine them within the same project to build for two different platforms within the single project.
Something that I was super surprised about is that there is no mac requirement to do a full build of the mac application. I wasn’t really up to date with how apps within MacOS are typically built, but I thought if they were anything like iOS you would need a mac just to deploy the thing. No such requirement here (Although I suspect you will have one anyway if you actually intend to develop mac applications).
One big thing. When I actually did all of this, there was a whole host of issues actually getting the project to run. Weirdly enough, updating Visual Studio itself was enough to get everything up and running (You need to do this *before* you create the project). So ensure you are on the latest version of VS.
So how does it actually look when run? Let’s put Windows and Linux side by side.
Definitely some interesting things right off the bat. Mostly that on Linux, we don’t really use Menu Bars, instead they are similar to a Mac where along the top of the window you have your “File” option etc. Also that the sizing is vastly different between the two, both in height and width! The main point is, we managed to build a GUI application sharing the exact same code, and have it run on Windows and Linux! Cool!
One final thing, you can use Visual Studio to add new forms/components instead of typing them up manually. In reality, it doesn’t really do that much boiler plate for you, but it’s there if you need it. Just right click your shared code project, and select Add New Item as you typically would. You should have a new option of adding an “Eto.Forms View”. From here you are given options on what you are trying to create (A panel, dialog or form), and how you want it to be designed (Code, XAML, Json etc).
Setup From A Terminal/Command Prompt
Alright, so you are one of “those” people that want to use a terminal/command prompt everywhere. Well that’s ok, Eto has you covered! In reality because there is no WYSIWYG designer, there isn’t any great need for Visual Studio if you prefer to use VS Code. Realistically the only difference is how you create the initial project template (Since Visual Studio extensions are going to be off the cards).
The first thing we are going to do is install the Eto.Forms templates. To do that, we run a specific dotnet command in our terminal/command prompt.
To see all available options to us, we can run :
But we are pros and know exactly what we want. So we run :
What this does is create a solution in the current directory (Named after the folder name). It creates a solution for us because of the -sln flag. The -m flag tells us which “mode” we want to use for designing our forms (In our case we want to use code). And finally -s says to create separate projects for each platform. And that’s it! We have a fully templated out project that is essentially identical to the one we created in Visual Studio.
One more thing, you should also be able to create “files” in a similar way to creating them in Visual Studio. So it does a bit of boiler plate legwork for you. To see all available options to you, you can run :
Again, it’s basically creating a class with the right inheritance and that’s about it. But it can be handy.
Related Posts
- Setting Up VS Code For ASP.net Core Development
- How To Fix : “This version of Microsoft.AspNetCore.App is only compatible […]”
- Error MSB4025: The Project File Could Not Be Loaded
- Using Yeoman With ASP.net Core