代码之家  ›  专栏  ›  技术社区  ›  astef

如何使用dotnet sln将所有项目添加到单个解决方案中?

  •  2
  • astef  · 技术社区  · 7 年前

    以下示例来自 here

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

    但我有个错误:

    **/*.csproj .

    1 回复  |  直到 7 年前
        1
  •  6
  •   astef    7 年前

    基于Unix/Linux的终端支持全局模式

    我的Windows PowerShell解决方案如下:

    $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 ""$_""" }
    
        2
  •  1
  •   Gordon Rudman    6 年前

    在Windows上,还可以使用以下命令递归地将子目录中的所有项目添加到预先存在的解决方案文件中:

    FOR /R %i IN (*.csproj) DO dotnet sln add "%i"
    

    或者,如果需要经常(重新)创建解决方案文件,则可以创建包含以下内容的批处理文件,然后在需要时运行它:

    dotnet new sln 
    FOR /R %%i IN (*.csproj) DO dotnet sln add "%%i"