【发布时间】:2020-05-18 13:32:52
【问题描述】:
考虑以下项目结构:
- 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
这一切都有效,但是代码生成工具需要在我正在运行的每个 API 项目作业上运行,这使得我的构建速度很慢。 我希望有某种方法只运行一次代码生成工具,然后所有 API 项目都可以使用生成文件的数据项目中的二进制文件?
理想情况下,我必须能够在单独的作业中预构建数据项目,将 dll 作为工件发布,然后在后续的 API 构建中使用这些 dll。我猜dotnet build --no-dependencies 可以做到这一点,但这意味着我还需要单独构建其他所有内容,从可维护性的角度来看,这是不可取的。
【问题讨论】: