如何创建 YAML 文件以支持 .NET 6、.NET 7、.NET 8?

问题描述 投票:0回答:1

我的项目有多个框架 net6.0;net7.0;net8.0

我创建了一个 YAML 文件,一切正常,但是当我将其设置为 .NET 8 时,这意味着单个框架。

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Release'

steps:
- script: echo 'Starting the build'
  displayName: 'Starting Build'

- script: dotnet restore
  displayName: 'Restore Dependencies'

- script: dotnet build --configuration $(buildConfiguration) --no-restore
  displayName: 'Build Project'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: true
    arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory) -property:TargetFramework=net8.0'
    zipAfterPublish: false
  displayName: 'Publish Artifact'


- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)'
    artifact: 'myAppBuild'
    publishLocation: 'pipeline'
  displayName: 'Publish Build Artifact'

我需要一个支持 .NET 6、.NET 7 和 .NET8 的解决方案

azure azure-devops yaml azure-pipelines
1个回答
0
投票

您可以使用对象类型运行时参数将所有三个目标框架传递给构建作业。

parameters:
- name: TargetFrameworks
  type: object
  default:
    - 'net8.0'
    - 'net7.0'
    - 'net6.0'

steps:
- script: echo 'Starting the build'
  displayName: 'Starting Build'

- script: dotnet restore
  displayName: 'Restore Dependencies'

- script: dotnet build --configuration $(buildConfiguration) --no-restore
  displayName: 'Build Project'

- ${{ each Framework in parameters.TargetFrameworks }}:
  - task: DotNetCoreCLI@2
    displayName: 'Publish Artifact - ${{ Framework }}'
    inputs:
      command: publish
      publishWebProjects: true
      arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/${{ Framework }} -property:TargetFramework=${{ Framework }}'
      zipAfterPublish: false

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)'
    artifact: 'myAppBuild'
    publishLocation: 'pipeline'
  displayName: 'Publish Build Artifact'

© www.soinside.com 2019 - 2024. All rights reserved.