How to add a Project (.csproj) to Solution (.sln) under a Solution Folder using dotnet CLI (command line)?
Asked Answered
S

4

52

I am trying to add a csproj to a sln using dotnet sln command line.

Adding the project is easily achievable using the below command.

  dotnet sln todo.sln add todo-app/todo-app.csproj

But how do I add the same under a Solution Folder

Socinian answered 22/7, 2018 at 18:5 Comment(0)
D
30

As of .NET Core 3 (preview, test with 3.0.100-preview7-X)

dotnet sln solution.sln add --solution-folder foo1\foo2\foo3 bar.csproj

It creates a nested hierarchy as of

solution.sln
|
└───foo1
│   │
│   └───foo2
│       │
│       └───foo3
│            │   bar
│            │   ...

Downrange answered 3/8, 2019 at 17:26 Comment(1)
This is the only correct answer here, OP asked to add project under a specific solution folderOssuary
U
53

Please try below code to add project to a solution from projects sub folder

dotnet sln ../todo.sln add todo-app.csproj 
Used answered 7/11, 2018 at 11:2 Comment(1)
tool tip of add a comment link says to avoid answering questions in comments.Used
D
30

As of .NET Core 3 (preview, test with 3.0.100-preview7-X)

dotnet sln solution.sln add --solution-folder foo1\foo2\foo3 bar.csproj

It creates a nested hierarchy as of

solution.sln
|
└───foo1
│   │
│   └───foo2
│       │
│       └───foo3
│            │   bar
│            │   ...

Downrange answered 3/8, 2019 at 17:26 Comment(1)
This is the only correct answer here, OP asked to add project under a specific solution folderOssuary
M
22

Follow these steps:

  1. dotnet new sln --name "your solution name"
  2. dotnet sln add "path of your .csproj file along with the name"

Example: If your name of the solution file would be "MyProject.sln" and the csproj is in same path then

  1. dotnet new sln --name MyProject.sln
  2. dotnet sln add MyProject.csproj
Manakin answered 29/4, 2021 at 10:53 Comment(1)
I like this answer because it omits the optional explicit providing of name of .sln fileAccomplish
S
12

If you're using PowerShell or bash the below command is handy:

dotnet sln path_to_solution.sln add (ls -r **/*.csproj)

or simply:

dotnet sln add (ls -r **/*.csproj)
Sunil answered 8/10, 2022 at 19:16 Comment(1)
also try $ dotnet sln add $(ls -r **/*.csproj) when using zshStadtholder

© 2022 - 2025 — McMap. All rights reserved.