Skip to main content

Commands to create a new .NET core project.

#!/usr/bin/env bash

#
# Based on: https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test#commands-to-create-the-solution
#

# Create a new solution file "MySolution.sln" under the "MySolution" direcotory.
dotnet new sln -o "MySolution"

# cd to to the newly created directory "MySolution":
cd "MySolution"

# Create a new class library project "MyProject.csproj" under the "src" directory:
dotnet new classlib -o "src/MyProject"

# Rename the default class "Class1.cs" to "MyProject.cs":
mv "src/MyProject/Class1.cs" "src/MyProject/MyProject.cs"

# Attach the class library project "MyProject.csproj" to the solution "MySolution.sln":
dotnet sln add "src/MyProject/MyProject.csproj"

# Create a new Xunit unit test project "MyProject.Tests.csproj" under the "test" directory:
dotnet new xunit -o "test/MyProject.Tests"

# Add a reference to the class library project "MyProject.csproj" in the unit test project "MyProject.Tests.csproj":
dotnet add "test/MyProject.Tests/MyProject.Tests.csproj" reference "src/MyProject/MyProject.csproj"

# Rename the default unit test class "UnitTest1.cs" to "MyProjectTests.cs":
mv "test/MyProject.Tests/UnitTest1.cs" "test/MyProject.Tests/MyProjectTests.cs"

# Attach the unit test project "MyProject.Tests.csproj" to the solution "MySolution.sln":
dotnet sln add "test/MyProject.Tests/MyProject.Tests.csproj"