Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Free course! Predicting the Future, Estimating, and Running Your Projects with Flow Metrics

Cheat Sheet: Use dotnet.exe to Create New Solutions, Projects, & References


I’ve been playing with .NET Core a lot lately and I’ve been trying to stick to the command line and Visual Studio Code as much as possible so that I can really learn what’s going on so I can (eventually) do cross-platform devops-y things.  This means that I’m spending a lot of time with dotnet.exe…which is kind of an adventure because the documentation’s a little spotty right now.

Here are some things that I’ve figured out.  A lot of these commands are dependent on what directory you’ve currently CD’d to the command prompt window.  The commands that create/edit projects or solutions assume that you’ve CD’d to the directory that where that file should be created or already exists.  The create solution & project commands use the name of the directory to create the solution & project files.

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.]

Create a new Solution (*.sln):

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

Create a new Class Library (*.csproj):

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

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

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

Create a new ASP.NET MVC project:

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

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

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

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

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

Add a project (*.csproj) to a Solution (*.sln):

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:

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:

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

Use dotnet to do a build:

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

 

I hope this dotnet cheatsheet helps!

-Ben

SUBSCRIBE TO THE BLOG


One response to “Cheat Sheet: Use dotnet.exe to Create New Solutions, Projects, & References”

  1. […] on my post about how to do some common Solution and Project tasks using the dotnet command, here’s a sample script to create a complete solution that can be used from Visual Studio […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.