With a continuous integration and release pipeline configured and working, I was going back through projects and creating the necessary build and release tasks. One build job however was failing with the following error:
2016-03-04T13:04:26.3021168Z Set workingFolder to default: D:\TFS\tasks\NuGetInstaller\0.1.16 2016-03-04T13:04:26.3391205Z Executing the powershell script: D:\TFS\tasks\NuGetInstaller\0.1.16\NuGetInstaller.ps1 2016-03-04T13:04:26.6061472Z D:\TFS\agent\worker\tools\NuGet.exe restore "d:\TFS\_work\1\s\src\MySolution.sln" -NonInteractive 2016-03-04T13:04:26.9761842Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'. 2016-03-04T13:04:27.0951961Z ##[error]There are duplicate packages: log4net.1.2.10 2016-03-04T13:04:27.1041970Z ##[error]Unexpected exit code 1 returned from tool NuGet.exe
The error causing the job to fail is:
There are duplicate packages
Checking The Build
So I checked out the project and compiled with Visual Studio, no problems. Then I tried using the nuget command from the command line.
D:\Projects\MySolution\src>nuget restore ll packages listed in packages.config are already installed.
The packages folder already exists so we have to clear it first. Since I have Cygwin installed (and I prefer the Unix tools), I just deleted the folder from the command line:
rm -rf Packages
You can obviously do this from the Windows explorer shell or use the native DOS commands.
So running the command again, all of the packages restore without issue. Hmmm…
Replicating The Error
So next, I run the identical command that was logged in the log output for the build job:
D:\TFS\_work\1\s\src>D:\TFS\agent\worker\tools\NuGet.exe restore "d:\TFS\_work\1\s\src\MySolution.sln" -NonInteractive MSBuild auto-detection: using msbuild version '12.0' from 'C:\Program Files (x86)\MSBuild\12.0\bin'. There are duplicate packages: log4net.1.2.10
And now we finally get the error to duplicate.
Let’s check the versions of our NuGet utility.
On the build server, we have:
D:\TFS\_work\1\s\src>D:\TFS\agent\worker\tools\NuGet.exe nuget Version: 220.127.116.1181
On the workstation with Visual Studio (with NuGet specified in the path), we have:
D:\Projects\MySolution\src>nuget NuGet Version: 2.8.50926.602
Different NuGet Versions
So the build server is using the 3.x branch of NuGet which doesn’t handle XML errors as gracefully (or is more strict) as the prior version. So now we know the cause of the problem, let see if we can find the duplicate.
And sure enough, inside of a subproject we have the following inside of the packages.config file:
<package id="log4net" version="1.2.10" targetFramework="net45" /> <package id="log4net" version="1.2.10" targetFramework="net45" />
Remove the dupliate line, recommit and push the code.