简体   繁体   English

.Net Core 构建解决方案

[英].Net Core build a solution

If you try to run from the command line in the top directory of a solution made with visual studio:如果您尝试从使用 Visual Studio 制作的解决方案的顶级目录中的命令行运行:

dotnet build

My solution is architectured like that:我的解决方案是这样架构的:

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

it will fail with the following error:它将失败并出现以下错误:

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

How could I build the solution without having to specify each project explicitely (and then without the related maintenance) ?我如何构建解决方案而不必明确指定每个项目(然后没有相关维护)?

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

You can use wildcards like that from the top directory (where lies the .sln).您可以使用顶级目录(.sln 所在的位置)中的通配符。

  • With the project.json in SolutionDir/Src/ProjectName :使用SolutionDir/Src/ProjectNameproject.json

    dotnet build */**/project.json

  • If project.json in SolutionDir/ProjectName :如果在SolutionDir/ProjectName project.json

    dotnet build **/project.json

Note: It's recommended to migrate to new csproj project format to get support and new features.注意: 建议迁移到新的 csproj 项目格式以获得支持和新功能。

Since .NET Core 1.0 RTM从 .NET Core 1.0 RTM

The solution is back for good.解决方案又回来了。

  dotnet build solution.sln

In powershell, build all csproj file under the current directory.在powershell中,构建当前目录下的所有csproj文件。

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

If you arrive here looking for the command to build a SLN with dotnet CLI (v3.1.X), using only CLI args, it's below.如果您到达这里寻找使用dotnet CLI (v3.1.X) 构建 SLN 的命令,仅使用 CLI args,它在下面。

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

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

To add to the answer, if you are publishing the project, use dotnet publish src\\MyProject1\\ to publish all the files.补充一点,如果您要发布项目,请使用dotnet publish src\\MyProject1\\发布所有文件。

Publishing will include files defined to be included in project.json.发布将包括定义为包含在 project.json 中的文件。

With dotnet CLI 2.1, it could build the solution.使用 dotnet CLI 2.1,它可以构建解决方案。 Here is my config:这是我的配置:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET 核心解决方案生成出现 GenerateDepsFile 错误 - .NET Core solution build gives a GenerateDepsFile error .NET Core迁移解决方案中的WebHostBuilder.Build()MissingMethodException - WebHostBuilder.Build() MissingMethodException in .NET Core migrated solution 如何在 Mac 或 linux 上的 .NET Core 上构建多目标解决方案? - How to build multi-target solution on .NET Core on Mac or linux? Appveyor CI无法使用数据库项目构建.net core 2.1解决方案 - Appveyor CI fails to build a .net core 2.1 solution with a database project 无法构建包含 .Net Core 和 SQL 项目的解决方案 - Unable to build a solution which contains .Net Core and SQL projects .NET Core 消息队列解决方案 - .NET Core message queue solution .net核心中StreamReader的更短解决方案 - A shorter solution to StreamReader in .net core .net核心解决方案 - 项目结构 - .net Core Solution - Project stucture VS 2017如何构建和测试包含.Net Core的混合解决方案 - How does VS 2017 build and test a mixed solution containing .Net Core Cake 构建脚本在 Azure Devops 中使用混合 .NET 核心和框架解决方案失败 - Cake build script fails in Azure Devops with mixed .NET core and framework solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM