Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 619
Kishore Sahasranaman Avatar asked Jul 22 '18 18:07

Kishore Sahasranaman


People also ask

How do I add a .csproj file to a solution?

Adding a project to a solution file Once you have a solution file, you can add a project to it using the sln add command, and provide the path to the project's . csproj file. This will add the project to an existing solution file in the current folder.

How do I add a project reference in dotnet core?

One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.


4 Answers

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

dotnet sln ../todo.sln add todo-app.csproj 
like image 53
Suraj Avatar answered Oct 21 '22 05:10

Suraj


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

like image 43
Eric Liu Avatar answered Oct 21 '22 07:10

Eric Liu


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
like image 30
Sudip Ghosh Avatar answered Oct 21 '22 06:10

Sudip Ghosh


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)
like image 1
AliReza Sabouri Avatar answered Oct 21 '22 07:10

AliReza Sabouri