Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core: How to create solution folders from the command line

Tags:

.net-core

I am organising a new project, and I would like to create as much of it as possible from the command line.

I like to put my test projects into a solution folder. However, the command dotnet sln add seems somewhat restricted. Its argument list seems to consist only of a list of project files to add.

Is there a way of specifying a solution folder (as opposed to a physical folder) when adding newly created projects (test projects in my case, but the question is more general)?

like image 442
Rob Lyndon Avatar asked Apr 09 '18 13:04

Rob Lyndon


People also ask

How do I create a solution folder?

Create Solution Folders Right-click on the solution → Add → New Solution Folder (or with the solution selected, click the Project menu → Add New Solution Folder):


4 Answers

At the moment it is not possible, you need create the physical structure folder like the solution structure folders

dotnet new <typeproj> --output "physical/domain" --name "domain"

dotnet new <typeproj> --output "physical/service" --name "service"

after open the solution with visual studio, create the "physical" solution folder and add the previous projects that you already have ready

like image 129
ch2o Avatar answered Oct 25 '22 00:10

ch2o


I just accomplished this using .Net Core 2.2 by adding a new project to Tests\UnitTests\UnitTests.csproj folder first, then running the dotnet sln add from the solution root.

Initial Folder Structure

Initial Folder Structure

Adding UnitTest.csproj inside Tests\UnitTests

Ran from folder containing TestMvcCore2.sln

dotnet new classlib -o .\Tests\UnitTests -n UnitTests

Adding UnitTest.csproj to TestMvcCore2.sln

Ran from folder containing TestMvcCore2.sln

dotnet sln add .\TestMvcCore2.sln  .\Tests\UnitTests\UnitTests.csproj

Creates a Tests solution file in the visual studio sln

enter image description here

like image 24
w00ngy Avatar answered Oct 24 '22 23:10

w00ngy


From this Microsoft Docs

dotnet sln yoursolution.sln add pathofyourproject\yourprojectfile.csproj --solution-folder solutionfoldername

If the solution folder doesn't exist, this command create a new solution folder. In the other cases, this command add a project to your solution folder.

like image 27
PiemP Avatar answered Oct 24 '22 22:10

PiemP


As mentioned in Microsoft Docs, if you want to create new solution, you have to write dotnet new sln. This command will create a solution file in current directory named with the name of current directory. Also, you can specify the name of output solution file by dotnet new sln -o <SOLUTION_NAME>. This will also create a folder with the name you specify. To add projects to this solution enter in command prompt: dotnet sln <YOUR_SOLUTION_NAME> add <PROJECT_YOU_WANT_TO_ADD> <PROJECT_YOU_WANT_TO_ADD> <PROJECT_YOU_WANT_TO_ADD> ... This will add all the projects you've specified with its folders to the solution you've specified.

like image 26
Viacheslav Avatar answered Oct 24 '22 22:10

Viacheslav