Skip to content

Instantly share code, notes, and snippets.

Last active April 19, 2023 19:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
cheatsheet dotnet command line commands to quickly setup new projects and solution

How to create a scaffold for .NET project

Create the folders

mkdir MyProject

cd MyProject

mkdir src test

Create the project files

dotnet new classlib -o src/Library

dotnet new xunit -o test/Library.Tests

dotnet add test/Library.Tests/Library.Tests.csproj reference src/Library/Library.csproj

Making a Web API

dotnet new webapi -o src/WebApi

Making a console application

dotnet new console -o src/MyConsole

Run the tests

dotnet test test/Library.Tests/Library.Tests.csproj

Or run and watch for changes

dotnet watch --project test/Library.Tests/ test

Create the solution file

-n is optional, will default to folder name

dotnet new sln -n MyProject

Add projects to solution

dotnet sln MyProject.sln add src/Library/Library.csproj test/Library.Tests/Library.Tests.csproj

Run tests from solution

dotnet test MyProject.sln

Or run and watch tests from solution

dotnet watch --project MyProject.sln test

Run console application with input file

touch input.txt

dotnet run --project src/MyConsole/MyConsole.csproj < input.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment