Run Dotnet Core App On Mac

  • ASP.NET Core is the latest web framework from Microsoft that supports development with C# and the.NET Framework. In this latest incarnation of ASP.NET, you can choose to use an alternative.NET framework called.NET Core in order to deliver on some amazing new promises from the Microsoft team.
  • Developing ASP.NET Core Applications on a Mac With Visual Studio Code ¶ Start Visual Studio Code Tap File Open and navigate to your Empty ASP.NET Core app From a Terminal / bash prompt, run dotnet restore to restore the project’s dependencies.
  • 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. For windows an exe.
  • You can see in the Win10 folder there's my 'MYAPPLICATION.exe' (mine is called scd.exe) that can be run, rather than running things like developers do with 'dotnet run.' There's lots of good documentation about how you can tune and define exactly what gets deployed with your self contained application over at the.NET Core Docs.
Sponsored By
Run Dotnet Core App On Mac

Select the option to install.NET Core. Installing Xamarin is optional for.NET Core development. For more information, see the following resources: Tutorial: Install Visual Studio for Mac. Supported macOS versions.NET Core versions supported by Visual Studio for Mac. Create a.NET Core console app project named 'HelloWorld'. .NET Core 2.1 downloads for Linux, macOS, and Windows.NET Core is a cross-platform version of.NET, for building apps that run on Linux, macOS, and Windows.

Just in case you missed it, .NET is all open source now and .NET Core is a free, open source, cross-platform framework that you can download and start with in <10 minutes. You can get it on Mac, Windows, and a half-dozen Unixes at http://dot.net. Take that along with the free, cross-platform Visual Studio Code and you'll be writing C# and F# all over the place.

Ok, that said, there's two ways to deploy a .NET Core application. There's FDD and SCD. Since TLAs (three letter acronyms) are stupid, that's Framework-dependent and Self-contained. When .NET Core is installed it ends up in C:program filesdotnet on Windows, for example. In the 'Shared' folder there's a bunch of .NET stuff that is, well, shared. There may be multiple folders, as you can see in my folder below. You can have many and multiple installs of .NET Core.

When you're installing your app and its dependencies BUT NOT .NET Core itself, you're dependent on .NET Core already being on the target machine. That's fine for Web Apps or systems with lots of apps, but what if I want to write an app and give it to you as zip or on a USB key and and I just want it to work. I'll include .NET Core as well so the whole thing is a Self Contained Deployment.

It will make my 'Hello World' application larger than if I was using an existing system-wide install, but I know it'll Just Work because it'll be totally self-contained.

If I deploy my app along with .NET Core it's important to remember that I'll be responsible for servicing .NET Core and keeping it up to date. I also need to decide on my target platforms ahead of time. If I want it to run on Windows, Mac, and Linux AND just work, I'll need to include those target platforms and build deployment packages for them. This all makes mostly intuitive sense but it's good to know.

I'll take my little app (I'm just using a 'dotnet new' app) and I'll modify project.json in a text editor.

My app is a .NETCore.App, but it's not going to use the .NET Core platform that's installed. It'll use a local version so I'll remove 'type='platform' from this dependency.

Next I'll make a runtimes section to specify which ones I want to target. There's a list of ALL the Runtime IDs here.

After running 'dotnet restore' you'll want to build for each of these like this:

And then publish release versions after you've tested, etc.

Once this is done, I've got my app self-contained in n folders, ready to deploy to whatever systems I want.

You can see in the Win10 folder there's my 'MYAPPLICATION.exe' (mine is called scd.exe) that can be run, rather than running things like developers do with 'dotnet run.'

Mac

There's lots of good documentation about how you can tune and define exactly what gets deployed with your self contained application over at the .NET Core Docs. You can do considerable trimming to .NET Core, and there's talk of that becoming more and more automated in the future, possibly down to the method level.

Sponsor: Big thanks to Redgate for sponsoring the feed this week. Discover the world’s most trusted SQL Server comparison tool. Enjoy a free trial of SQL Compare, the industry standard for comparing and deploying SQL Server schemas.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.


AboutNewsletter

Coming from a Windows background I took the plunge recently and swapped to a Mac. This has given me the perfect opportunity to get into .NET Core! In this post I'm going to take you through getting everything you need to get setup and create your first app.

Prerequisites

Lets just go over a few things to get us started

.Net Core

Now we have chosen an editor the next thing we need to do is install .Net Core itself.

Regardless of which editor you choose this step will install the required command line tools or project templates to get started. Head over here to download the SDK and follow the installation steps.

NodeJS & NPM

Finally we need to install NodeJS and NPM which are found here. We need them both so we can install Yeoman, bower and any other packages in the future. Once installed run the following command.

Just for reference, Yeoman is a template generator and will be used to scaffold our .Net Core app.

Creating the Application with Yeoman

Now we need to install the ASP.Net Core template generator. This will be used by Yeoman to generate our application.

For anyone unsure, the -g flag specifies that this package will be installed globally.

All thats left before we create our first app is to make a directory to put it in. I'm just going to create a directory in my Home folder and then move into it using the following commands.

The moment of truth is here, let's fire the command to generate our app.

You should be presented with some text asking if you want to submit some anonymous usage data, answer either yes or no. Next you'll be asked what type of application you want to create, select Web Application Basic [without Membership and Authorisation].

Then choose which UI framework you want to use, I went with Sematic UI purely because I've not used it before. But choose which ever framework you feel comfortable with.

Install Dotnet Core Mac

Finally give your application a name, I've gone with the classic Hello World.

Once you have completed the above steps then Yeoman will go off and create the app. And you should then be left with some like the screenshot below.

Building & Running the App

Run Dotnet Core App On Mac Windows 10

We have been left us with some commands to run in order to get our application going. Let's work through those and hopefully we should be able to view our shiny new app.

cd HelloWorld - Changes to the new application folder created by Yeoman.

dotnet restore - Restores all Nuget packages required by the application.

dotnet build - This is an optional step as the run command does a build anyway.

Run Dotnet Core App

dotnet run - As mentioned above this builds everything then spins up a server on localhost port 5000 in order to view the app.

If all has gone according to plan you should see the following in the terminal.

Open your favourite browser and navigate to http://localhost:5000 and you should be looking at your new ASP.Net Core Application.

Run Asp.net Core App On Mac

Wrapping Things Up

Net Core Mac

Dotnet

Run Dotnet Core Console App

So there you have it, a working ASP.Net Core application on Mac! I hope you found this post useful.