Search code examples
azure-devopsnugetazure-pipelinesnuget-package

How to specify which version of nuget.exe to use with self-hosted agent in Azure DevOps?


I'm running self-hosted agent and NuGetToolInstaller was always throwing an error ERR:unable to get local issuer certificate.

I found a fix-hack here. Just to download needed nuget.exe version to the machine, add it to Environment Variables and remove NuGetToolInstaller at all. It fixed the issue, but today I understood that it's not really so.

Currently, I have nuget.exe version 5.6.0 so I thought self-hosted agent uses it but...

While running Initialize Job Azure downloads NuGetCommand

enter image description here

I found the location and can see that it downloads three different versions of nuget.exe

enter image description here

And it always uses 4.1.0 for any NuGetCommand.

enter image description here

How can I specify which version of NuGet to use without NuGetToolInstaller?

Or how to make Initialize Job not downloading any nuget.exe and just use that one available in the system?

For testing I deleted everything from the yaml and it looks like this:

trigger:
- master
pool:
  name: somePool    
jobs:
- job: someJob  
  variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'  
  steps:
    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'

Solution

  • From the pipeline log, it seems nuget task use v4.1 by default:

    enter image description here

    If you don't want to use NuGetToolInstaller task, one workaround is replacing the nuget.exe with the version you want to use in the {agent work folder}\_tool\NuGet\4.1.0\x64 folder.