Starting a New ASP.NET Core 2.2 C# Project with Visual Studio for Mac

This article will walk beginners through creating a new project from scratch. You won’t be adding any custom functionality by the end of the article and it only covers the basics plus some best practices. Other articles in this series will go deeper.

Assumptions:

  • You have programmed in C#.
  • You have used Visual Studio for Mac.

Install Visual Studio for Mac

If you don’t already have Visual Studio for Mac installed, you can download it from visualstudio.com. This guide is for the Mac OS version of Visual Studio, not the Windows version. The Windows version can be found here.

Download the Mac version of Visual Studio

When you run the Visual Studio installer, it is going to ask you which Platforms you want to install. You need to select .NET Core + ASP.NET Core.

Select .NET Core + ASP.NET Core Platform

Install the .NET SDK 2.2

You will also need the .NET Core 2.2 SDK. You can download it here.

Download the x64 version of the SDK for macOS

Create a New Project

Run Visual Studio and Select File > New Solution.

Select the ASP.NET Core Web App (MVC) project

On the left menu select .NET Core > .App.

On the list of application templates pick ASP.NET Core Web App (MVC) or ASP.NET Core Web App. The later will create an application using the newer Razor Pages framework.

On the next screen pick .NET Core 2.2 as the Target Framework. If you don’t see it listed, install the SDK as listed above.

Target .NET Core 2.2

The next screen you name you project and choose some options.

Project settings

Name your project and pay attention to where the project location will be. Leaving the Solution name the same as the Project name is fine. Some people prefer to name the web project to a more specific name like MyProject.Web instead of MyProject. This can always be changed later.

I would recommend keeping the Create a project directory within the solution directory checked to keep your file system cleaner.

Check Use .git for version control and Create a .gitignore file to ignore inessential files if you plan on checking this project into a source control repository like GitHub.

Click Create and your project will be setup. You should be able to build the application now.

Default solution structure

If you try to run it now and this is your first website on you might get an error.

Certificate error

The application will run using HTTPS by default. No site should launch without this. You need to trust this certificate by running the suggested command from a Terminal window.

dotnet dev-certs https --trust

You should now be able to run your application.

Application running

Some Minor Changes

Technically you are ready to go. But let me give you a few tips on some changes you should make.

If your application name has more than 1 word, put spaces in the name in the _Layout.cshtml file. You will find it in 3 places:

  1. The title tag in head.
  2. The site name in header.
  3. The site name in footer.

Notice the scroll bar is always showing on the right? It’s a bug in the current version of the CSS for the site. Near the very bottom of the site.css file, reduce the line height of the footer by 1 pixel. That should fix it.

line-height: 59px; /* Vertically center the text there */

It’s a good idea to get an up to date start. So ahead and update any NuGet packages that may already be out of date.

I’ll have more tips on customizing your project setup in the future. Be sure to follow me so you don’t miss out.

Have fun coding!

Software developer specializing in Microsoft technologies.