I keep migrating my build scripts into CakeBuild system. And I keep running them on VSTS. Because mostly VSTS build system is awesome, it is free for small teams and has a lot of good stuff in it.
But working with NuGet on VSTS is for some reason a complete PITA. This time I had trouble with restoring NuGet packages:
'AutoMapper' already has a dependency defined for 'NETStandard.Library'.
An error occurred when executing task 'Restore-NuGet-Packages'.
Error: NuGet: Process returned an error (exit code 1).
System.Exception: Unexpected exit code 1 returned from tool Cake.exe
This is because Automapper is way ahead of times and VSTS uses older version of nuget.exe. If I run the same code locally, I don’t get this error. So I need to provide my own nuget.exe
file and rely on that. This is how it is done in Cake script:
Task("Restore-NuGet-Packages")
.Does(() =>
{
var settings = new NuGetRestoreSettings()
{
// VSTS has old version of Nuget.exe and Automapper restore fails because of that
ToolPath = "./lib/nuget.exe",
Verbosity = NuGetVerbosity.Detailed,
};
NuGetRestore(".\MySolution.sln", settings);
});
Note the overriding ToolPath
– this is how you can tell Cake to use the specific .exe file for the operation.