Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add all projects to a single solution with dotnet sln?

Following examples from here I'm trying to execute

dotnet sln AllProjects.sln add **/*.csproj

But I get this error:

Could not find project or directory **/*.csproj.

Looks like wildcards are not working. What am I doing wrong?

like image 261
astef Avatar asked Aug 25 '18 12:08

astef


People also ask

How do I add a project to a sln 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. The path to the project can be absolute or relative, but it will be added as a relative path in the .

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.

Should I place solution and project in the same directory?

Since a solution is a container of projects, it does not make sense for the solution file to be inside the project directory.


2 Answers

I've missed this statement:

Globbing patterns are supported on Unix/Linux based terminals

My Windows PowerShell solution looks like this:

$projects = Get-ChildItem -Recurse | Where-Object { $_.Name -match '^.+\.(csproj|vbproj)$' }

$uniqueProjects = $projects | Group-Object -Property Name | Where Count -EQ 1 | select -ExpandProperty Group | % { $_.FullName }

Invoke-Expression -Command "dotnet new sln -n AllProjects"

$uniqueProjects | % { Invoke-Expression -Command "dotnet sln AllProjects.sln add ""$_""" }
like image 157
astef Avatar answered Oct 21 '22 18:10

astef


For Windows, open PowerShell and run this command to add all projects to the solution file:

 dotnet sln add (ls -r **/*.csproj)
like image 30
Matt Sage Avatar answered Oct 21 '22 19:10

Matt Sage