My .NET Core Setup for MacOS/Linux
Tags: dotnet, core, docker, sqlserver
Published: 2018-10-13 00:20:08

---
title: My .NET Core Setup for MacOS/Linux
published: true
description: Can you smell that? Yeah, that's the smell of freedom!
tags: dotnet, core, docker, sqlserver
cover_image: https://thepracticaldev.s3.amazonaws.com/i/rjs0ogje8q8rb5cne1xo.jpeg
---

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

- [.NET Core SDK](https://www.microsoft.com/net/download).
- [Docker](https://www.docker.com/).
- [VS Code](https://code.visualstudio.com/) (free) / [Rider](https://www.jetbrains.com/rider/download/#section=mac) (paid or free for some students).
- [Azure Data Studio](https://docs.microsoft.com/en-us/sql/azure-data-studio/download?view=sql-server-2017) (This one is similar to SQL Management Studio).

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](https://dev.to/reverentgeek) that can teach you exactly how to do it and even more!

{% link https://dev.to/reverentgeek/sql-server-running-on-a-mac-29e %}

# To editor or not to editor

Over on the _Tools_ section I mentioned you could either use [VS Code](https://code.visualstudio.com/) or [Rider](https://www.jetbrains.com/rider/download/#section=mac), 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](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) 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:

```csharp
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](https://thepracticaldev.s3.amazonaws.com/i/tq48oq68htt043j9m3fb.png)

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](https://thepracticaldev.s3.amazonaws.com/i/3e0guy47oqj6mifo4yz5.png)

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](https://thepracticaldev.s3.amazonaws.com/i/8x92o9vnqp7ehoyd9g4j.png)

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](https://media.giphy.com/media/MCZ39lz83o5lC/giphy.gif)

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.