0
votes

I am setting up an Azure Build pipeline to automatically build when a NuGet package get's published. In that build definition - I want to install the latest version of the package.

According to this answer, I need to restore packages first to authenticate against Dev Ops feeds.

I have set-up a build.yml file to include these tasks:

- task: DotNetCoreCLI@2
  displayName: 'Restore Packages'
  inputs:
    command: restore
    projects: web/*.csproj
    vstsFeed: organizational-packages

- task: DotNetCoreCLI@2
  displayName: Install Custom Internal Package Package
  inputs:
     command: 'custom'
     custom: 'add'
     arguments: 'package Custom.Internal.Package --prerelease'
     projects: 'Web/*.csproj'
     feedsToUse: 'select'
     feedRestore: 'organizational-packages'

The NuGet feed is hosted in Azure Dev ops and has organizational scope.

When I go to run the build - the Azure Package feed is not included in the search for the package:

info : Adding PackageReference for package 'Custom.Internal.Package' into project 
'/home/vsts/work/1/s/Project.Web/Web.csproj'.
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/custom.internal.package/index.json
info :   NotFound https://api.nuget.org/v3/registration5-gz-semver2/cbh.surescripts.business/index.json 202ms
error: There are no versions available for the package 'Custom.Internal.Package'.

The package is located at https://myorg.pkgs.visualstudio.com/_packaging/organizational-packages/nuget/v3/index.json

I even tried accomplishing this with just the command line tasks:

- task: NuGetAuthenticate@0
  displayName: Authenticate NuGet Feed

- task: CmdLine@2
  displayName: Add Organizational Package Source
  inputs:
    script: 'dotnet nuget add source https://myorg.pkgs.visualstudio.com/_packaging/organizational-packages/nuget/v3/index.json -n credible'

- task: CmdLine@2
  displayName: Install Custom Internal Package
  inputs:
    script: 'dotnet add package Custom.Internal.Package--prerelease'
  workingDirectory: '$(Build.SourcesDirectory)/Web'

In the later case the package source is added - but I am getting an unauthorized error:

info : Adding PackageReference for package 'Custom.Internal.Package' into project '/home/vsts/work/1/s/Project.Web/Web.csproj'.
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/custom.internal.package/index.json
info :   NotFound https://api.nuget.org/v3/registration5-gz-semver2/custom.internal.package/index.json 64ms
error: Unable to load the service index for source https://myorg.pkgs.visualstudio.com/_packaging/organziational-packages/nuget/v3/index.json.
error:   Response status code does not indicate success: 401 (Unauthorized).
1

1 Answers

1
votes

There is no feedsToUse in custom command in DotNetCoreCLI task, you could remove it, and try to add -v|--version <VERSION> to version the package:

- task: DotNetCoreCLI@2
  displayName: 'dotnet custom'
  inputs:
    command: custom
    projects: 'Web/*.csproj'
    custom: add
    arguments: 'package Custom.Internal.Package --prerelease -v 1.0.0'