Nuget软件包在工件中不可用

时间:2020-09-23 14:54:24

标签: azure-devops nuget-package

我正在尝试通过azure管道推送私有nuget程序包。没有错误,但我看不到工件在我的提要中发布。这是我的yml文件。我在这里做错了什么或可以添加什么?

name: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
trigger:
 - master

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Release'
  version.MajorMinor: '4.0' 
  version.Revision: $[counter(variables['version.MajorMinor'], 0)]
  versionNumber: '$(version.MajorMinor).$(version.Revision)'

steps:

 - task: CmdLine@2
   inputs:
     script: 'dir'
     displayName: 'dotnet build $(buildConfiguration)'

 - task: DotNetCoreCLI@2
   displayName: 'dotnet build'
   inputs:
   command: 'build'
   arguments: '--configuration $(buildConfiguration)'
   projects: 'MyProj.csproj'

 - task: PowerShell@2
    displayName: Set the name of the build (i.e. the Build.BuildNumber)
    inputs:
    targetType: 'inline'
    script: |
         [string] $buildName = "$(Build.SourceBranchName)_$(versionNumber)"
         Write-Host "Setting the name of the build to '$buildName'."
         Write-Host "##vso[build.updatebuildnumber]$buildName"

   - task: DotNetCoreCLI@2
      displayName: "dotnet pack"
      inputs:
      command: 'pack'
      packagesToPack:  'MyProj.csproj'
      nobuild: true
      versioningScheme: 'byEnvVar'
      versionEnvVar: 'versionNumber'
     packDestination: '$(Build.ArtifactStagingDirectory)'

    - task: NuGetCommand@2
      inputs:
      command: 'push'
      packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
     nuGetFeedType: 'internal'
     publishVstsFeed: 'XXXXXXXXX/YYYYYYYYYYYY'
     allowPackageConflicts: true

1 个答案:

答案 0 :(得分:0)

要发布到Azure Artifacts feed,请将 Project Collection Build Service 标识设置为feed上的 Contributor 。并将以下代码段添加到您的azure-pipelines.yml文件中。

steps:
- task: NuGetAuthenticate@0
  displayName: 'NuGet Authenticate'
- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    command: push
    publishVstsFeed: '<projectName>/<feed>'
    allowPackageConflicts: true

请参阅此处的文档:

https://docs.microsoft.com/en-us/azure/devops/pipelines/artifacts/nuget?view=azure-devops&tabs=yaml