.net core dotnet生成,仅从生成中排除一个依赖项

.net core dotnet生成,仅从生成中排除一个依赖项,.net-core,azure-pipelines,.net Core,Azure Pipelines,考虑以下项目结构: MyProject.Api.a MyProject.Api.b MyProject.Data,由a和b引用 我在Azure devOps中设置了一个管道,它执行以下恢复、构建和发布操作: jobs: - job: api-a steps: - task: DotNetCoreCLI@2 displayName: Restore inputs: command: restore

考虑以下项目结构:

  • MyProject.Api.a
  • MyProject.Api.b
  • MyProject.Data,由a和b引用
我在Azure devOps中设置了一个管道,它执行以下恢复、构建和发布操作:

jobs:
  - job: api-a
    steps:
      - task: DotNetCoreCLI@2
        displayName: Restore
        inputs:
          command: restore
          projects: "MyProject.Api.a.csproj"
      - task: DotNetCoreCLI@2
        displayName: Build
        inputs:
          command: build
          projects: "MyProject.Api.a.csproj"
          arguments: "--configuration $(buildConfiguration)"
      - task: DotNetCoreCLI@2
        displayName: Publish
        inputs:
          command: publish
          projects: "MyProject.Api.a.csproj"
          publishWebProjects: false
          arguments: "--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/project-api-a-publish"
      - task: PublishPipelineArtifact@1
        displayName: Publish release Artifact
        inputs:
          targetPath: "$(Build.ArtifactStagingDirectory)/project-api-a-publish"
          artifactName: "a-publish"
  - job: api-b
    steps:
      - task: DotNetCoreCLI@2
        displayName: Restore
        inputs:
          command: restore
          projects: "MyProject.Api.b.csproj"
      - task: DotNetCoreCLI@2
        displayName: Build
        inputs:
          command: build
          projects: "MyProject.Api.b.csproj"
          arguments: "--configuration $(buildConfiguration)"
      - task: DotNetCoreCLI@2
        displayName: Publish
        inputs:
          command: publish
          projects: "MyProject.Api.b.csproj"
          publishWebProjects: false
          arguments: "--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/project-api-b-publish"
      - task: PublishPipelineArtifact@1
        displayName: Publish release Artifact
        inputs:
          targetPath: "$(Build.ArtifactStagingDirectory)/project-api-b-publish"
          artifactName: "b-publish"
问题是MyProject.Data不能从源代码构建,它需要先运行一个外部工具来生成一些C#类。在此步骤之前,项目将无法构建。 所以我补充说:

      - task: DotNetCoreCLI@2
        displayName: "Restore tools"
        inputs:
          workingDirectory: "MyProject.Data"
          command: custom
          custom: tool
          arguments: restore --interactive --configfile ../NuGet.config
      - task: DotNetCoreCLI@2
        displayName: my-codegen-tool
        inputs:
          workingDirectory: "MyProject.Data"
          command: custom
          custom: tool
          arguments: run my-codegen-tool
这一切都是可行的,但是codegen工具需要在我正在运行的每个API项目作业上运行,这使得我的构建非常缓慢。 我希望有办法只运行一次codegen工具,然后所有API项目都可以使用生成文件的数据项目中的二进制文件


理想情况下,我必须能够在单独的作业中预构建数据项目,将dll作为工件发布,然后在后续API构建中使用这些dll。我猜这在
dotnet build中是可能的——没有依赖关系,但这意味着我还需要单独构建其他所有内容,从可维护性的角度来看,这是不可取的。

您可以尝试将多个作业合并到一个作业中。首先通过前两个任务生成所需的C#类,然后在dotnet生成任务中使用通配符(例如,所有子文件夹中的所有.csproj文件都使用*/*.csproj)生成。 您可以考虑删除还原任务,因为dotnet还原是在dotNETBug中隐式运行的。p> 这说明:您不必运行
dotnet restore
,因为它由所有需要进行还原的命令隐式运行,例如
dotnet new、dotnet build、dotnet run、dotnet test、dotnet publish和dotnet pack
。要禁用隐式还原,请使用
--no restore
选项

- job: 
    steps:
      - task: DotNetCoreCLI@2
        displayName: "Restore tools"
        inputs:
          workingDirectory: "MyProject.Data"
          command: custom
          custom: tool
          arguments: restore --interactive --configfile ../NuGet.config
      - task: DotNetCoreCLI@2
        displayName: my-codegen-tool
        inputs:
          workingDirectory: "MyProject.Data"
          command: custom
          custom: tool
          arguments: run my-codegen-tool
      - task: DotNetCoreCLI@2
        displayName: Build
        inputs:
          command: build
          projects: "**/*.csproj"
          arguments: "--configuration $(buildConfiguration)"