0

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).
JDBennett
  • 1,323
  • 17
  • 45

1 Answers1

1

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'
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • I want to be able to install the latest package. Not a specific version – JDBennett Mar 05 '21 at 17:59
  • If you run the `dotnet add` command locally, how's the result? – Cece Dong - MSFT Mar 08 '21 at 10:03
  • I can do this locally. Once I add the Azure Dev Ops artifact repo as a source - dotnet nuget add source {url} -n package-source. I can then run dotnet add package .... without specifying a version - the latest (including pre-releases) is added to the .csproj. Why can I not use the dev ops package source in the pipeline? – JDBennett Mar 08 '21 at 16:27
  • Could you please set variable `system.debug` to `true`, and check whether there is more information? You could mask personal information and share the log. – Cece Dong - MSFT Mar 09 '21 at 10:02