27

如果您尝试从使用 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

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

4

4 回答 4

38

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

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

  • 随着project.jsonSolutionDir/Src/ProjectName

    dotnet build */**/project.json

  • 如果project.jsonSolutionDir/ProjectName

    dotnet build **/project.json

注意:建议迁移到新的 csproj 项目格式以获得支持和新功能。

自 .NET Core 1.0 RTM

解决方案又回来了。

  dotnet build solution.sln

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

foreach ($csproj in $(Get-ChildItem -Recurse . -Filter *.csproj) )
{
    dotnet build $csproj.FullName
}
于 2016-06-22T07:47:03.260 回答
5

如果您到这里寻找使用dotnetCLI(版本 > 3.1)构建 SLN 的命令,仅使用 CLI args,则如下所示。

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

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

于 2020-08-20T13:31:55.490 回答
0

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

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

于 2016-08-29T12:49:00.933 回答
0

使用 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
            }
        },
于 2018-07-18T13:35:40.960 回答