我在 Visual Studio 2019 中有一个 .NET MVC 解决方案,其中包含 3 个项目:
- AdminWebApp
- SharedCode(在 VS 中的其他两个项目中设置为依赖项)
- FrontWebApp
在 Azure DevOps Pipelines 中,我想为其创建单独的构建
AdminWebApp
和
FrontWebApp
其中都包含
SharedCode
因为它包含助手等。我想用 YAML 方式来完成它。 我应该创建 1 或 2 个管道(每个工件稍后将发布到其自己的 Azure 应用服务)?实现它的YAML代码是什么?
最佳答案
管理和发布周期的样子确实很重要。最纯粹的方法是每次都重新部署所有内容。现实的方法是在有意义的情况下将部署管道分组在一起。
就以“YAML 方式”做什么而言。会考虑使用 YAML templates
模板参数至少会由项目的目录来构建。这是 .net Core 模板的示例,但可以让您了解思考过程:出于示例目的,此 YAML 文件将被称为诸如 build-corewebapp.yml 之类的内容
parameters:
SolutionPath: ''
BuildConfiguration: 'Release'
projectName: ''
DependsOn: []
publish: 'false'
jobs:
- job: Build_${{ parameters.projectName }}
dependsOn: ${{ parameters.DependsOn }}
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: 'restore'
projects: '$(Build.SourcesDirectory)/${{ parameters.SolutionPath }}/${{ parameters.projectName }}**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
projects: '$(Build.SourcesDirectory)/${{ parameters.SolutionPath }}/${{ parameters.projectName }}**/*.csproj'
arguments: '--configuration ${{ parameters.BuildConfiguration }}'
- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
command: test
projects: '$(Build.SourcesDirectory)/${{ parameters.SolutionPath }}/${{ parameters.projectName }}.Tests/*.csproj'
arguments: '--configuration ${{ parameters.BuildConfiguration }} --collect "Code coverage" '
- job: Publish_${{ parameters.projectName }}
dependsOn: Build_${{ parameters.projectName }}
condition: and(succeeded(),eq( ${{ parameters.publish }}, 'true'))
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: false
projects: '$(Build.SourcesDirectory)/${{ parameters.SolutionPath }}/${{ parameters.projectName }}**/*.csproj'
arguments: '--configuration ${{ parameters.BuildConfiguration }} --output $(build.artifactstagingdirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
模板将被类似的东西调用:
jobs:
- template: build-corewebapp.yml
parameters:
projectName: ${{ variables.appProjectName }}
solutionPath: $(solutionPath)
publish: 'true'
为了获得最大的可重用性,我会推荐任何类型的 build template to exist in a separate repository so it can be used by other repos 。这将通过引用类似于以下内容的存储库在您的管道中进行设置:
resources:
repositories:
- repository: repositoryTemplate
type: git
name: ProjectName/YAMLTEMPLATERepoName
使用模板的优点是可以在一个地方更新和引用更新任务版本或更改构建/部署策略。
关于asp.net-mvc - 使用 YAML 的 Azure DevOps Pipeline 用于解决许多项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63283063/