Skip to main content

This cheatsheet is courtesy Ben Day and is available here. This Markdown file is just for easy reference for programmers.

---
title: Dotnet Core Cheat Sheet
subtitle: This cheat sheet is courtesy Ben Day
author: Ben Day
date: August 22, 2017
source: https://gist.github.com/nth-block/fc2d8b6619f5218820324817bf8cbe0c
notoc: false
---

This cheat sheet is courtesy Ben Day and is available [here](https://www.benday.com/2017/02/10/cheat-sheet-use-dotnet-exe-to-create-new-solutions-projects-references/). This Markdown file is just for easy reference for programmers.

What follows are the excerpts from Ben's blog.

> The nice thing about the items on this 'cheat sheet' is that they work on Windows, Mac, and Linux.
> Note 2/13/2017: Want an example script? [Check this out.](https://www.benday.com/2017/02/10/script-create-new-asp-net-core-project-with-class-library-tests/)

## Create a new Solution (`*.sln`)

```bash
cd {directory where you want to create the *.sln file}
dotnet new sln
```

## Create a new Class Library (`*.csproj`)

```bash
cd {directory where you want to create the *.csproj file}
dotnet new classlib
```

## Create a new Class Library (`*.csproj`) targeting .NET Core

```bash
cd {directory where you want to create the *.csproj file}
dotnet new classlib -f netcoreapp2.1
```

## Create a new ASP.NET MVC project

```bash
cd {directory where you want to create the *.csproj file}
dotnet new mvc
```

## Create a new ASP.NET MVC project targeting .NET Core

```bash
cd {directory where you want to create the *.csproj file}
dotnet new mvc -f netcoreapp2.1
```

## Create a new MSTest unit test project targeting .NET Core

```bash
cd {directory where you want to create the *.csproj file}
dotnet new mstest -f netcoreapp2.1
```

## Add a project (`*.csproj`) to a Solution (`*.sln`)

```bash
cd {directory that contains the *.sln file}
dotnet sln MySolutionFile.sln add .\src\MySolution.WebUi\MySolution.WebUi.csproj
```

## Add a reference from one Project to another

```bash
cd {directory that contains the source/from *.csproj file}
dotnet add reference ..\MySolution.Api\MySolution.Api.csproj
```

## Restore NuGet dependencies so that you can be ready to do a build

```bash
cd {directory that contains the *.sln file or *.csproj file}
dotnet restore
```

## Use dotnet to do a build

```bash
cd {directory that contains the *.sln file or *.csproj file}
dotnet build
```