DEV Community

Cover image for My .NET Core Setup for MacOS/Linux
Christian Vasquez
Christian Vasquez

Posted on • Updated on

My .NET Core Setup for MacOS/Linux

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
Enter fullscreen mode Exit fullscreen mode

And

docker --version
Docker version 18.06.1-ce, build e68fc7a
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

mkdir CoreIsAwesome
Enter fullscreen mode Exit fullscreen mode

Then navigate to it with:

cd CoreIsAwesome
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

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!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

I used:

dotnet new mvc
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

And that should give you all the instructions you need.

Oldest comments (23)

Collapse
 
yaser profile image
Yaser Al-Najjar • Edited

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 !

Collapse
 
chrisvasqm profile image
Christian Vasquez

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.

Collapse
 
yaser profile image
Yaser Al-Najjar • Edited

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.

Thread Thread
 
ptupitsyn profile image
Pavel Tupitsyn

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).

Collapse
 
themulti0 profile image
Multi

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

Collapse
 
elanhasson profile image
Elan Hasson

I am spoiled by resharper!

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

Collapse
 
galdin profile image
Galdin Raphael

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 :)

Collapse
 
themulti0 profile image
Multi

Cool blog! Helpful for beginners!

Collapse
 
webreaper profile image
Mark Otway

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...

Collapse
 
chrisvasqm profile image
Christian Vasquez

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 😆.

Collapse
 
webreaper profile image
Mark Otway

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

Thread Thread
 
chrisvasqm profile image
Christian Vasquez

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

Thread Thread
 
jacobduijzer profile image
Jacob Duijzer

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

Collapse
 
equiman profile image
Camilo Martinez • Edited

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

Collapse
 
webreaper profile image
Mark Otway • Edited

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.

Thread Thread
 
equiman profile image
Camilo Martinez

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.

Thread Thread
 
webreaper profile image
Mark Otway • Edited

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.

Thread Thread
 
equiman profile image
Camilo Martinez

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.

Thread Thread
 
webreaper profile image
Mark Otway

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.

Collapse
 
zaratedev profile image
Jonathan Zarate

Nice!

Collapse
 
heinekeg profile image
Heinekeg

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.

Collapse
 
equiman profile image
Camilo Martinez • Edited

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.

Collapse
 
chrisvasqm profile image
Christian Vasquez

Thanks for sharing, Camilo!