Using the latest NuGet in your build
NuGet (both the command-line tool and the accompanying tools built into Visual Studio) continues to iterate rapidly and add support for new .NET Core and .NET Standard target frameworks, among other improvements. Naturally, many users of Team Build in Visual Studio Team Services want to build those apps, and we’ve seen some support issues because the version of NuGet used in the ‘NuGet’ build task by default is 4.0.0, which throws various error messages when trying to build these new project types.
We’ve made a few updates to make this experience better.
NuGet 4.3+ in VSTS and TFS 2018
If you’re using VSTS or the upcoming TFS 2018 release, new template-based builds will work automatically thanks to a new “NuGet Tool Installer” task that’s been added to the beginning of all build templates that use the NuGet task. Right now, the templates request NuGet 4.3; we’ll periodically update the default for new builds around the same time we install Visual Studio updates on the Hosted build agents.
For existing builds, add or update a NuGet Tool Installer step to select the version of NuGet to be used in your build.
NuGet 4.3+ in TFS 2017 Update 2 and earlier
Because the NuGet Tool Installer is not available in TFS versions prior to TFS 2018, there is a recommended workaround to use versions of NuGet > 4.0.0 in Team Build.
- Add the task, if you haven’t already. If you have a “NuGet Restore” step in the catalog (it may be in the Deprecated tasks section), insert it into your build. Otherwise, insert a “NuGet” step.
- For your NuGet/NuGet Installer step, use the version selector under the task name to select version “0.*”.
- In the Advanced section, set the NuGet Version to “Custom” and the Path to NuGet.exe as
- Check this PowerShell script (based on the original script by GitHub user leftler) into your repository.
- Before your NuGet step, add a “PowerShell” step, select “File Path” as the Type, select the file you checked in as the Script Path, and enter “4.3.0” (or any version of NuGet from this list) as the Arguments.