I set the repositoryPath with a relative location (.\packages) in nuget.config wich is under my code base's root path. It can restore/build in visual studio 2017. However, it failed in vsts build task because it can not locate the packages.
The reason is that NuGet restore install would copy the nuget.config to a tempory file then run the restore command which cause the repository path is not relative to my code base's root path.
In order to fix this problem, i have to add a copy files task to copy the packages into the right location.
Does the Nuget Task really need to copy the nuget.config to a tempory file?
The task copies the NuGet.config to a temporary location to safeguard the credentials used for authenticated feeds. However, there's a "Destination directory" setting further down in the task that you can use to specify a restore location relative to your code base - can you give that a shot?
The work around is not convenient because every build task will have a hard coded convention that already exists in the NuGet.config. You may 100 build definitions ... 100 build tasks with this folder hard coded.
Another issue is that this error is not easy to debug, so every time an engineer forgets to write the destination directory, hours of investigation are wasted.
@dudamir Makes sense, thanks. We're working with the NuGet team on their #6486, which will enable us to do auth without constructing a temporary nuget.config.
Any info on when this fix will be available?
It's not stated here, so for anyone that finds this, you can use $(System.DefaultWorkingDirectory) to reference the root of your repo. So, for example, my nuget.config has the repository path set like this:
<add key="repositorypath" value="Packages" />
I needed to set the destination directory to $(System.DefaultWorkingDirectory)/Packages.
Setting it to Packages/ creates a packages folder relative to every solution file it finds, and /Packages puts it on the root of the agent's hard drive.
Most helpful comment
It's not stated here, so for anyone that finds this, you can use $(System.DefaultWorkingDirectory) to reference the root of your repo. So, for example, my nuget.config has the repository path set like this:
<add key="repositorypath" value="Packages" />
I needed to set the destination directory to $(System.DefaultWorkingDirectory)/Packages.
Setting it to Packages/ creates a packages folder relative to every solution file it finds, and /Packages puts it on the root of the agent's hard drive.