使用 .NET 5 在 Azure Devops 管道期间创建通用包

Create Universal Package during Azure Devops Pipeline using .NET 5

几天来一直卡在这个问题上...需要有关 Azure Devops 管道中的 YAML 文件的帮助。我升级到 .NET 5,但现在我的通用包没有正确构建。

背景:

我在 Azure Devops 中创建了一个新项目并配置了一个常规管道和一个发布管道。初始(常规)管道未打包正确的通用包。我通过使用 Azure CL 下载文件对其进行了测试,其中没有 zip 文件。

以下是我的 YAML 文件:

# ASP.NET Core (.NET Framework)
# Builds and publishes a new version of each project in the solution as a nuget package in the Artifacts Feed

name : 5.1$(Rev:.r)

# TRIGGER WHEN WE CHECK IN CODE
trigger:
- master

# RUN THIS PIPELINE IN WINDOWS
pool:
  vmImage: 'windows-latest'

# USE THESE VARIABLES
variables:
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  universal: 'artifact.web' # the name of the Universal package in the Artifacts feeds

# PERFORM THESE STEPS USING NUGET & MSBUILD: 
# 1. RESTORE from nuget
# 2. BUILD solution
# 3. PACK nuget packages
# 4. PUSH packages to Artifacts feed
# 5. Create the Universal Artifacts 

steps:
- task: UseDotNet@2
  inputs:
    version: '5.0.x'
    includePreviewVersions: true # Required for preview versions
    
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.4.1'
  inputs:
    versionSpec: 4.4.1
    checkLatest: true

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    feedsToUse: 'select'
    vstsFeed: 'ae385ab4-48a5-4c76-b207-dfd1050b8ebf/4b05f135-0b1d-48ad-a8e6-d26bf03c2aae' 
    
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
  displayName: 'dotnet build $(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'byEnvVar'
    versionEnvVar: 'Build.BuildNumber'
    includesymbols: true 

- task: NuGetCommand@2
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'ae385ab4-48a5-4c76-b207-dfd1050b8ebf/4b05f135-0b1d-48ad-a8e6-d26bf03c2aae'
    allowPackageConflicts: true

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: '$(Build.ArtifactStagingDirectory)'
    publishLocation: 'pipeline'


- task: UniversalPackages@0
  displayName: Universal Publish
  inputs:
    command: publish
    publishDirectory: '$(Build.ArtifactStagingDirectory)'
    vstsFeedPublish: 'ae385ab4-48a5-4c76-b207-dfd1050b8ebf/4b05f135-0b1d-48ad-a8e6-d26bf03c2aae'
    vstsFeedPackagePublish: '$(universal)' # the name of the Universal package in the Artifacts feeds
    packagePublishDescription: '$(universal)'

管道成功完成,但未创建代表通用包的 zip 文件。

当我 运行 发布管道时,出现此错误:

##[error]Error: No package found with specified pattern.<br/>Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.

知道如何在 Azure Devops Pipelines 中构建合适的通用文件吗?

我试过你的代码并在发布管道中成功下载了包。

可能是你在release pipeline中获取包的路径不对,并不是没有生成包。

你可以使用Universal Package task下载包看看是否成功

如果是,请检查您下载包的任务。 通用包不存储为 zip 文件。如果您以 zip 格式获取包,则很可能会失败。另外,你可以点击build log中的artifact,看看你的路径是否正确。

如图: dotnetcore.5.1.2.nupkg 文件的路径应该是 D:\a\r1\a\Job\dotnetcore.5.1.2.nupkg.

问题是没有使用最新版本的 Nuget。

将此添加到我的 YAML

- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 5.8.0'
  inputs:
    versionSpec: 5.8.0