Search code examples
c#.netprojects-and-solutionssolutiondotnet-cli

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?


Solution

  • 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 ""$_""" }