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)?
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):
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
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
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With