Unable to load the service index for source azure devops

While creating Nuget package through Azure DevOps pipeline and adding the package to the Artifacts, you might get the following or similar errors:

error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/MyEnterpriseApps/_packaging/SchemaRegistry%40Local/nuget/v3/index.json

This could usually happen when you’re Publishing the package to Nuget in a separate job or Stage from the Build step.

To resolve this, you need to do a nuget package restore before publishing the package to Nuget:

steps:
  - task: DotNetCoreCLI@2
    displayName: Nuget package restore
    inputs:
      command: restore
      projects: '$(workingDirectory)/**/$(projectName)*.csproj'
      feedsToUse: 'config'
      nugetConfigPath: $(workingDirectory)/nuget.config
  - task: DotNetCoreCLI@2
    displayName: Create Nuget Package
    inputs:
        command: pack
        versioningScheme: byBuildNumber
        arguments: '--configuration $(buildConfiguration)'
        packagesToPack: '$(workingDirectory)/**/$(projectName).csproj'
        packDestination: '$(Build.ArtifactStagingDirectory)'
  - task: NuGetAuthenticate@0
    displayName: 'NuGet Authenticate'
  - task: NuGetCommand@2
    displayName: 'NuGet push'
    inputs:
      command: push
      publishVstsFeed: 'MyFramework'
      allowPackageConflicts: true

The variables in the above template can be passed from a Pipeline that is triggered by a change to a branch or run manually.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.