provide credentials in nuget command line parameters

If you're using an Azure Pipelines build file and trying to push to a private feed, you can use these snippets, just make sure to update $VARIABLES and indentation as-needed:

      - task: NuGetAuthenticate@0
        displayName: "Auth NuGet"
        name: Nuget_Authenticate
        inputs:
          nuGetServiceConnections: '$PROJECT_SETTINGS_SERVICE_CONNECTION_NAME'
          forceReinstallCredentialProvider: true

      - task: NuGetCommand@2
        name: pushNuGetPkg
        displayName: "Push NuGet"
        inputs:
          command: 'push'
          packagesToPush: '$(Build.Repository.Localpath)\Packages\*.nupkg'
          nuGetFeedType: 'external'
          publishFeedCredentials: '$ARTIFACTS_FEED_NAME'
          publishVstsFeed: '$AZURE_ORGANIZATION_NAME/$ARTIFACTS_FEED_NAME'

You may also need to set these env-vars up in your ADO Project's Library -> Defaults section. Make sure the second one is securely masked with the Lock icon.

NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED: true

VSS_NUGET_EXTERNAL_FEED_ENDPOINTS: {"endpointCredentials": [{"endpoint":"https://$AZURE_ORG_NAME.pkgs.visualstudio.com/_packaging/$ARTIFACTS_FEED_NAME/nuget/v3/index.json", "username":"$USERNAME", "password":"$PAT"}]}


You have to change the NuGet.config you use. That is possible from the command line:

nuget sources add -Name "MyExample" -Source "XXX" -username "Y" -password "Z"

The password will be stored encrypted in the config file and can only be decrypted in the same user context as it was encrypted.


Use PAT (Personal Access Token) as the password. Make sure that PAT has packaging read and write permission.

Tags:

Nuget