【问题标题】:How to add all projects to a single solution with dotnet sln?如何使用 dotnet sln 将所有项目添加到单个解决方案中?
【发布时间】:2019-01-31 16:38:39
【问题描述】:

遵循here 的示例,我正在尝试执行

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

但我得到这个错误:

找不到项目或目录**/*.csproj

通配符似乎不起作用。我做错了什么?

【问题讨论】:

  • 操作系统是什么?
  • Windows、PowerShell
  • 您的项目是否在 .net core 中?
  • 不,他们不是
  • 不是 100%,但我认为 **/ 是基于 Linux 的...尝试 (dot) ./* 或 (dot)(dot) 如果你的备份一级

标签: c# .net projects-and-solutions solution dotnet-cli


【解决方案1】:

我错过了这个声明:

基于 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】:

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

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

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

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

    请注意,在批处理文件中尝试执行此操作时需要额外的 %。

    【讨论】:

      【解决方案3】:

      对于 Windows,打开 PowerShell 并运行此命令以将所有项目添加到解决方案文件:

       dotnet sln add (ls -r **/*.csproj)
      

      【讨论】:

        猜你喜欢
        • 2018-12-30
        • 1970-01-01
        • 1970-01-01
        • 2010-10-12
        • 2022-01-02
        • 2015-08-29
        • 2018-06-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多