5
votes

We are hosting TFS 2017 Update 2 on-prem, and using on-prem build agents. The latest version of NuGet.exe is currently 4.3.0, but our build agents always default to using v4.0.0. How can I get our build agents to use the latest version of NuGet.exe?

We need to update because NuGet restore is failing when using v4.0.0, but works with v4.3.0, since we are dealing with new .Net Standard 2.0 packages. On our build server I was able to do NuGet.exe update -self to update the NuGet.exe found at C:\Builds\_work\_tool\NuGet\4.0.0\x64\nuget.exe from 4.0.0 to 4.3.0, but that C:\Builds\_work\_tool directory regularly gets deleted and recreated, so this isn't a persistent workaround.

How can I get our build agents to always use the latest version of NuGet.exe, or at least v4.3.0?

2

2 Answers

6
votes

I know you're not supposed to answer with a link, but this post provides all the details you'll need, confirming that the task does indeed still use 4.0.0, how with VSTS and TFS 2018 you don't have to worry about this anymore (there's a new NuGet Installer task) and how to recreate that kind of task for VS 2017.2 (and earlier) via a PowerShell Script, Using the latest NuGet in your build

0
votes

Based on Greg's linked answer, but a little bit simpler:

  1. Add a step "NuGet Tool Installer" before the other NuGet steps, use ">=5.0.0" for the version and mark "Always download the latest matching version", this should - well - give you the latest stable version
  2. Replace the existing "NuGet Installer" steps - this seems to be the default with "NuGet Restore" steps, just copying the settings. They seem to be totally compatible, allowing e. g. for package config or solution files to be referenced, including pattern matching

NuGet TFS steps

That is it. Replacing the "NuGet Installer" that requires you to specify a version with the "NuGet Restore" that just uses the NuGet.exe from the path as set in "NuGet Tool Installer" is easier. Also mind the confusing naming (NuGet Tool Installer/NuGet Installer - the two are rather different).

Having to tinker so much with the not so old TFS 2017 infrastructure is a shame.