为什么我的 Azure Pipeline 中的 NuGet 包任务不使用我的 Azure Artifacts feed?

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

我的 Azure Pipeline 在使用 NuGet pack 命令时失败。这是错误:-

error NU1101: Unable to find package Repositories.Abstractions. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, Microsoft Visual Studio Offline Packages, nuget.org

这是失败的打包任务:-

  - task: DotNetCoreCLI@2
    displayName: Create NuGet Package
    inputs:
      command: 'pack'
      packagesToPack: '**/${{ parameters.nuGetPackageToBuild }}.csproj'
      versioningScheme: 'byBuildNumber'
      feedsToUse: 'select'
      vstsFeed: 'd4d1f2ae-4068-405e-93b1-etc. etc. etc. etc.'

它失败了,因为它没有使用我的 Azure Artifacts feed。以下是命令的输出,确认它没有尝试使用我的提要:-

使用的饲料:

https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
C:\Program Files\dotnet\library-packs

如您所见,我已将“feedsToUse”和“vstsFeed”参数添加到 pack 命令(上面)中,徒劳地希望它可以使用它们,但我已经知道 vstsFeed 参数仅在 NuGet 命令恢复时使用.

令我困惑的是,在同一个 Azure Pipeline 中,我有这个命令,它成功得很好(尽管它在不同的作业中):-

    - task: NuGetCommand@2
      name: 'NuGetRestore'
      displayName: 'NuGet Restore'
      inputs:
        command: 'restore'
        restoreSolution: '**/Osprey.NuGet.sln'
        feedsToUse: 'select'
        vstsFeed: 'd4d1f2ae-4068-405e-93b1-etc. etc. etc. etc.'

我不知道如何获取 pack 命令来使用 Azure Artifacts feed。有什么想法吗?

.net azure nuget pack artifacts
1个回答
0
投票

我尝试使用下面的管道,它适用于 Azure 工件源:-

确保在目录中的

nuget.config
文件中指定 nuget feed url:-

nuget.config:-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="AzureArtifacts" value="https://pkgs.dev.azure.com/xxxxxx38/_packaging/xxxxxxx738/nuget/v3/index.json" />
    <!-- Add other package sources if needed -->
  </packageSources>
</configuration>

Azure DevOps yaml 代码:-

trigger:
  branches:
    include:
      - master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

parameters:
- name: nuGetPackageToBuild
  type: string
  default: 'net6appdevops' 

steps:
- task: DotNetCoreCLI@2
  displayName: Create NuGet Package
  inputs:
    command: 'pack'
    packagesToPack: '**/${{ parameters.nuGetPackageToBuild }}.csproj'
    versioningScheme: 'byEnvVar'  
    versionEnvVar: 'BUILD_BUILDNUMBER'  
    feedsToUse: 'config'
    nugetConfigPath: '$(System.DefaultWorkingDirectory)/nuget.config'

输出:-

enter image description here

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