My .NET Core Setup for MacOS/Linux

Christian Vasquez - Oct 13 '18 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player