loading...
Cover image for My .NET Core Setup for MacOS/Linux

My .NET Core Setup for MacOS/Linux

chrisvasqm profile image Christian Vasquez Updated on ・4 min read

Crazy, right?

Who would have thought that Microsoft would make .NET development actually great outside of Windows!

I have the need to use these tools because of a subject I'm currently taking in college that requires me to do an ASP.NET MVC web application with Entity Framework and a few more fancy acronyms.

So, today I'll be going over the steps I took to get things started.

Before we start printing Hello World left and right, we gotta install a few tools:

Tools

In order to verify that everything went well, go ahead and execute the following commands in your Terminal:

dotnet --version
2.1.403

And

docker --version
Docker version 18.06.1-ce, build e68fc7a

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!

To editor or not to editor

Over on the Tools section I mentioned you could either use VS Code or Rider, so feel free to use which ever you prefer.

In case you go with VS Code, you will have to install the C# language extension and you are good to go.

I personally prefer using Rider because of my familiarity with IntelliJ based IDEs in terms of functionality and keyboard shortcuts overall. But for the sake of this post, I'll be going through the steps of using VS Code since it's the one recommended in the .NET Core website.

Hello World-ing

In order to start a project, the .NET Core SDK provides you with a few handy commands you can use in your Terminal.

To create a project, navigate to a folder of your preference by using the cd <folder-name> command, like:

cd Documents

Then create a folder by using the mkdir <folder-name> command:

mkdir CoreIsAwesome

Then navigate to it with:

cd CoreIsAwesome

Note: there's an important detail about this, if you use the next command to create a .NET Core project, it will be named just like the folder you are currenlty on, in this case "CoreIsAwesome".

Now we can generate a sample Console Application by using this:

dotnet new console

And you should quickly see something like this show up in your Terminal:

The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /Users/chrisvasqm/VisualStudioProjects/CoreIsAwesome/CoreIsAwesome.csproj...
  Restoring packages for /Users/chrisvasqm/VisualStudioProjects/CoreIsAwesome/CoreIsAwesome.csproj...
  Generating MSBuild file /Users/chrisvasqm/VisualStudioProjects/CoreIsAwesome/obj/CoreIsAwesome.csproj.nuget.g.props.
  Generating MSBuild file /Users/chrisvasqm/VisualStudioProjects/CoreIsAwesome/obj/CoreIsAwesome.csproj.nuget.g.targets.
  Restore completed in 211.77 ms for /Users/chrisvasqm/VisualStudioProjects/CoreIsAwesome/CoreIsAwesome.csproj.

Restore succeeded.

Now you should be able to see all your project's files in the Explorer panel.

If you select a file, let's say the Program.cs you should have the following code:

using System;

namespace CoreIsAwesome
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

And in a few seconds or so, VS Code should display a dialog like this:

Required assets dialog

Go ahead and click on "Yes".

Now, if you go over to the Debug panel, your Run Configuration should now be like this:

Run configuration

Which means we can go ahead and run our code!

Hit that green Play button while crossing your fingers so you don't get any errors.

Wait a few seconds until the build finishes...

Just a little more...

And...

Voila!

Hello World printed on the console

If you zoom in or squeeze your eyes hard enough, you should be able to see that tiny little "Hello World!" in the Debug Console.

But...

Remember, with great power comes great responsibility

In my particular case, the only difference is that instead of doing:

dotnet new console

I used:

dotnet new mvc

To have a .NET Core MVC template generated for me and then I had to set up Entity Framework Core dependencies in my project and so on, but that might be a topic for another post ;)

Tip: In case you might be curious about what other templates the dotnet new command can generate for you, use the following command:

dotnet new --help

And that should give you all the instructions you need.

Discussion

pic
Editor guide
 

Nice article, I'm using Windows with VS2017 for .NET Core developing.

Rider is great, but really, do you feel it has the same good look?

I hope one day a Resharper-like plugin will appear for VSCode... I'm done with VS2017, it's really bloated !

 

I agree. I cannot work without ReSharper though working on VS 2017 is a big pain.
And same thing, Rider lacks features and feels too lightweight and toolless than a fat heavy IDE such as Visual Studio

 

I am spoiled by resharper!

It automates so much. I miss it on every fresh VS install.

 

Hey Yaser,

I'm glad you liked it 😁.

"Rider is great, but really, do you feel it has the same good look?"

If you are referring to the overall UI and editor theme, I find it to be okay, although I've seen a few people using custom themes like Material Design looking ones to spice things up a little, I guess.

 

Man... Rider UI is great, but the UX sucks.
It looks like VS, but when you look closer, when you try to use it. It has a very ugly user experience. I just don't like it, and neither all my colleagues.

Quite the opposite, I find UX in Rider much better that in VS. For starters, almost everything can be done without touching the mouse. In particular, source control is MILES ahead of VS (or any other git tool, for that matter).

 

This, the material themes are excellent. I use one in vscode as well. Higher contrast, more legible icons, better spacing. Rider has fira code available ootb, hack is an easy addition

 

Any reason why you didn't use Visual Studio for Mac? I've been using it for over a year, and deploying stuff to a Linux box using Mono. Works really well, and no need for Windows. 😁

VS for Mac is getting better all the time...

 

Hey Mark,

No reason at all actually. Haven't really given it a try yet.

You could make s post about your experience using it πŸ˜†.

 

Could do! Tbh, not much to say other than it works. 😁

For me it's kind of like learning a new tool, comparing it to Window's version could result in an interesting article.

IMHO it Works great an has a few advantages over VS Code. Have been using it professionally for a few years now.

 

I gived a try, but it's not VS at all. It's more Xamarin IDE with another name.

 

Not sure when you tried it, but it's not that any more. I've never had any interest in Xamarin. Current version does full .Net projects, and also DotNetCore. It loads projects direct from VS2017 too.

8 months ago. It open and load all kind of projects but it's not the same as VS on Windows. But I'll take a look of current version, maybe now I'm wrong.

It's not the same as the Windows one, no. But it's a fully FLEDGED .net IDE. I've been using it to write .NET apps and utilities to run on my Linux server for over a year... See github.com/webreaper for examples.

Yeah, it's good alternative, but that's why I'm using VS Code... because it's the same no matter if you work on Win/Linux/Mac. No need to switch and rethink how work on each platform.

I use VS2017 all day at work, and VS for Mac when I code at home, and switching isn't a problem, as much as anything because OSX and Windows are different anyway.

 

Nice post!

A quick tip -- to create a quick project I do something like:

dotnet new console --name FooBar

That will create the console app within a FooBar folder with lesser keystrokes :)

 

That's one thing that is counterintuitive to me. A more common generation pattern would be something like dotnet new {template} {identity} --{flat option}. I'd expect at least identity to be mandatory, feels a bit like they're flipping the bit on the "create a folder for this project" standard they've had for years.

 

Some notes:

There's a docker image for SQL server for Linux you can add to your docker compose and go.

Datagrip is excellent for db coding tasks, since you already have jetbrains tools. For management tasks I still use the cli because old people reasons and toolability.

It's also fairly trivial to create your own dotnet CLI templates: docs.microsoft.com/en-us/dotnet/co...
I make use of this heavily as I prefer micro-orms and feel that server side rendering is an optimization rather than a starting point. I use .net core for creating services, then compose static assets/spas/graphql that build into their own containers from their own projects, then compose them to various deployable units.

 

One day I give a try with .Net Core on Mac with similar configuration... and now, 1 year before I don't miss VS on Windows at all.

I want to share my experience with Unit Testing, maybe can help others.

And how I solve one problem that is not ready implemented on .Net Core.

 

Thanks for sharing, Camilo!

 

Great article. I'm using the exact same setup for over 3 months, and i have no problems with it. I think i'll use a container to generate/run/build my projects, so i also get that out of the way.

New to .NET from PHP, but it's working great.

 
 

Cool blog! Helpful for beginners!