Starting a New ASP.NET Core 2.2 C# Project with Visual Studio 2017
By: Scott Kuhl
Tags: Microsoft, Aspnetcore

Install Visual Studio 2017

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

Download the Windows version of Visual Studio

When you run the Visual Studio installer, it is going to ask you which Workloads you want to install. You need to select either ASP.NET and web development under the Web & Cloud section and / or .NET Core cross-platform development under Other Toolsets.

Select the ASP.NET and web development Workload

Select the .NET Cor cross-platform development Workload

Install the .NET SDK 2.2

You will also need the .NET Core 2.2 SDK. Depending on when you have downloaded Visual Studio 2017, you may not have it yet. You can download it here. You will probably want to download the x64 installer. If you are not sure which version of Windows you are running, you can find it under Windows Settings > System > About.

Install the x64 Windows version of the 2.2 SDK

Create a New Project

Run Visual Studio 2017 and Select File > New Project.

On the left menu select Visual C# > .NET Core.

On the list of application templates pick ASP.NET Core Web Application. 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 directory for solution checked to keep your file system cleaner.

Check Create a new Git repository if you plan on checking this project into a source control repository like GitHub.

The next screen will ask a couple of important questions. Let’s go through each of these.

Template settings for a new project

Make sure that ASP.NET Core 2.2 is selected in the dropdown list. If you don’t see it, you need to install the SDK listed above and restart Visual Studio. Select Web Application (Model-View-Controller) or Web Application. The later will create an application using the newer Razor Pages framework. Leave Enable Docker Support unchecked unless you know what this is and plan to use it. Leave Configure for HTTPS checked. No site should launch without this. If you know you are going to have user accounts on your website, change the Authentication to Individual User Accounts with the option Store user accounts in-app. That will allow users to sign up on your site. There are more options available but this one is the most common.

Individual User Account settings

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

Default solution

Default solution with authentication

If you picked Individual User Accounts for authentication, you have an extra step before you can run it. Open the Package Manager Console window (under View > Other Windows > Package Manager Console) and run the Update-Database command.

Update the database from the Package Manager Console

You should now be able to run your application.

Application running without authentication

Application running with authentication

Some Minor Changes

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

Database Connection

If you picked Individual User Accounts for authentication your database name is going to be ugly. Open the appsettings.json file and change the name to your project name.

Before: Database=aspnet-MyFirstProjectWithUsers-98A44C6A-341D-46B3–8236–00A310A387A1;

After: Database=MyFirstProjectWithUsers;

Application Name

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:

The title tag in head. The site name in header. The site name in footer.

Scroll Bar Fix

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 */

Update Your NuGet Packages

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!