Creating a solution from the CLI

For folks that are on Windows and Visual Studio (not Code), solution files (.sln) are still pretty useful. Below follows the one-liner that I use to quickly create a new .csproj, .sln, and fire Visual Studio from the CLI. Console application: dotnet new console -n MyConsoleApp --use-program-main; cd MyConsoleApp; dotnet new sln; dotnet sln add MyConsoleApp.csproj; ii MyConsoleApp.sln; Web API: dotnet new webapi -n MyApi --use-program-main; cd MyApi; dotnet new sln; dotnet sln add MyApi.csproj; ii MyApi.sln;

Mar 8, 2025 - 23:17
 0
Creating a solution from the CLI

For folks that are on Windows and Visual Studio (not Code), solution files (.sln) are still pretty useful.

Below follows the one-liner that I use to quickly create a new .csproj, .sln, and fire Visual Studio from the CLI.

Console application:

dotnet new console -n MyConsoleApp --use-program-main; cd MyConsoleApp; dotnet new sln; dotnet sln add MyConsoleApp.csproj; ii MyConsoleApp.sln;

Web API:

dotnet new webapi -n MyApi --use-program-main; cd MyApi; dotnet new sln; dotnet sln add MyApi.csproj; ii MyApi.sln;