【问题标题】:Publish nuget package in azure devops from build or release pipeline从构建或发布管道在 azure devops 中发布 nuget 包
【发布时间】:2020-03-31 22:45:41
【问题描述】:

在 azure devops 中发布 nuget 包的正确位置在哪里?使用构建管道还是发布管道更好?

一种解决方案是在构建中创建一个工件 (zip) 并在发布中下载它并创建一个 nuget 包。

编辑

用条件任务解决它:

trigger:
  branches:
    include:
    - master
    - dev
  paths:
    include:
    - src/*
    - test/*
    - azure-pipelines.yml

pr:
  branches:
    include:
    - '*'

pool:
  vmImage: 'ubuntu-16.04'

variables:
  buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
  displayName: 'Use dotnet sdk 3.x'
  inputs:
    version: 3.x
    includePreviewVersions: false

- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
  displayName: Build_release
  inputs:
    command: build
    projects: '**/*.csproj'
    arguments: '--configuration release'

- task: DotNetCoreCLI@2
  condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
  displayName: Build_Debug
  inputs:
    command: build
    projects: '**/*.csproj'
    arguments: '--configuration debug'

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/*Test/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: NuGetToolInstaller@1
  displayName: 'Install nuget 5.x'
  inputs:
    versionSpec: '5.x'

- task: NuGetCommand@2
  displayName: 'Pack nuget'
  inputs:
    command: 'pack'
    packagesToPack: 'src/**/*.csproj'
    packDestination: '$(Build.ArtifactStagingDirectory)'

- task: NuGetCommand@2
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
  displayName: 'Push to nuget feed sample-cloud'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '<guid>'
    allowPackageConflicts: true

- task: NuGetCommand@2
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/dev')
  displayName: 'Push to nuget feed sample-cloud-dev'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '<guid>/<guid>'

【问题讨论】:

  • 只是检查提供的信息是否有用。如果您需要进一步的帮助,请告诉我们。
  • @LeoLiu-MSFT 我现在使用条件任务推送到正确的提要。您如何看待解决方案?

标签: .net azure .net-core azure-devops nuget


【解决方案1】:

从构建或发布管道在 azure devops 中发布 nuget 包

这绝对是你的个人喜好,是口味问题,没有标准要求或流程。

一般来说,发布包的过程是:构建项目/解决方案->打包.csproj/.nuspec文件生成nuget包->发布生成的包,我们不刻意拆分构建并将发布过程分为CICD,这样我们就不需要额外的管道开销,也不需要在构建和发布管道之间传递工件。

因此,我们可以通过 NuGet 任务packpush 生成包并在构建管道中发布包。

当然,如果包发布和CI、CD有严格的标准要求,我们需要在发布管道中发布包。例如,在构建管道中,我们生成了预发布包,但是如果我们要求只发布稳定版本包,那么在这种情况下,我们需要创建一个发布管道来发布stable 包,否则,我们必须在构建管道中手动启用/禁用推送任务。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-20
    • 2019-03-26
    • 2020-12-23
    • 2020-11-26
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多