【问题标题】:.Net Core build a solution.Net Core 构建解决方案
【发布时间】:2016-10-24 00:30:32
【问题描述】:

如果您尝试从使用 Visual Studio 制作的解决方案的顶层目录中的命令行运行:

dotnet build

我的解决方案是这样架构的:

MySolution.sln
   > src
       > MyProject1
           > project.json
       > MyProject2
           > project.json
   > test
       > MyProject.Test
           > project.json

它将失败并出现以下错误:

Couldn't find 'project.json' in current directory

我如何构建解决方案而无需明确指定每个项目(然后无需相关维护)?

【问题讨论】:

  • 问题是什么?
  • @berkser 现在应该更清楚了

标签: .net-core dotnet-cli


【解决方案1】:

如果您来到这里寻找使用 dotnet CLI(版本 > 3.1)构建 SLN 的命令,仅使用 CLI args,它在下面。

dotnet build <PATH>/<TO>/<SLN_FILE>.sln

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build#arguments

【讨论】:

    【解决方案2】:

    .NET Core 1.0 预览版 (project.json)

    您可以使用顶级目录(.sln 所在的位置)中的通配符。

    • SolutionDir/Src/ProjectName 中使用project.json

      dotnet build */**/project.json

    • 如果project.jsonSolutionDir/ProjectName

      dotnet build **/project.json

    注意:It's recommended to migrate to new csproj project format to get support and new features.

    从 .NET Core 1.0 RTM 开始

    解决方案又回来了。

      dotnet build solution.sln
    

    在powershell中,构建当前目录下的所有csproj文件。

    foreach ($csproj in $(Get-ChildItem -Recurse . -Filter *.csproj) )
    {
        dotnet build $csproj.FullName
    }
    

    【讨论】:

    • 我必须修改答案才能让它工作:dotnet build **/project.json
    • 你可以使用像flubu(fluent builder)这样的工具来让事情变得更容易。更多关于:stackoverflow.com/questions/40890522/…
    【解决方案3】:

    使用 dotnet CLI 2.1,它可以构建解决方案。 这是我的配置:

            {
                "label": "build",
                "command": "dotnet",
                "type": "process",
                "args": [
                    "build",
                    "${workspaceFolder}/SolutionName.sln",
                    "/property:GenerateFullPaths=true"
                ],
                "problemMatcher": "$msCompile",
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            },
    

    【讨论】:

      【解决方案4】:

      添加答案,如果您要发布项目,请使用dotnet publish src\MyProject1\ 发布所有文件。

      发布将包含定义为包含在 project.json 中的文件。

      【讨论】:

        猜你喜欢
        • 2018-10-08
        • 2021-04-26
        • 2020-12-07
        • 2011-12-24
        • 2019-04-22
        • 1970-01-01
        • 2018-12-20
        • 2018-08-22
        • 2019-08-03
        相关资源
        最近更新 更多