I'm using version 2.0.5 of the nuget task and version 4.3.0-preview3 of nuget.exe via the NuGet Tool Installer task.
I encountered a build break because my nuget.config specifies a source that points to a (relative) local path within my source repo:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="LocalPackages" />
</packageSources>
<disabledPackageSources />
</configuration>
In my solution, nuget.config and the LocalPackages folder are both within the 'src' folder.
When the nuget task runs, it copies my nuget.config to a temporary file under the _work1\Nuget folder:
E:\A\_work\1\Nuget\tempNuGet_876538.config
Because it's no longer under 'src', this causes a failure when nuget tries to connect to the LocalPackages feed. Here's the error:
2017-07-21T15:51:36.1805770Z Failed to retrieve information about 'NETStandard.Library' from remote source 'E:\A\_work\1\Nuget\LocalPackages'.
2017-07-21T15:51:36.1825770Z NuGet.Protocol.Core.Types.FatalProtocolException: Failed to retrieve information about 'NETStandard.Library' from remote source 'E:\A\_work\1\Nuget\LocalPackages'.
2017-07-21T15:51:36.1825770Z at NuGet.Protocol.LocalV3FindPackageByIdResource.GetVersionsCore(String id, ILogger logger)
2017-07-21T15:51:36.1825770Z at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
2017-07-21T15:51:36.1825770Z at NuGet.Protocol.LocalV3FindPackageByIdResource.GetVersions(String id, SourceCacheContext cacheContext, ILogger logger)
2017-07-21T15:51:36.1835773Z at NuGet.Protocol.LocalV3FindPackageByIdResource.GetAllVersionsAsync(String id, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
2017-07-21T15:51:36.1835773Z at NuGet.Commands.SourceRepositoryDependencyProvider.<GetAllVersionsAsync>d__24.MoveNext()
I was able to work around it by adding a task to update the LocalPackages feed to an absolute path using 'nuget sources remove' followed by 'nuget sources add')
Thanks for reporting this.
We recommend using Team Services Package Management instead of checking your packages into your source tree.
An alternate work around is to add the absolute path to the folder on the build agent via environment variable - e.g.
<add key="Local" value="%BUILD_SOURCESDIRECTORY%\LocalPackages" />
The environment variable will be resolved in the build, but not resolved on your local machine.
@jotaylo In my case I am consuming a private nuget package from another team that is not available on our VSTS packaging feed. In the long term, I agree - getting them to use VSTS packaging would be appropriate.
I'll try the environment variable workaround (I think it needs an extra dot to avoid making the local machine case an absolute path from root). Thanks for the suggestion.
Ran into this same issue the other day with a NuGet package containing a hotfix that had to be included in the repo. The environment variable workaround didn't work for me so I had to add an extra build step to run a shell script (I'm on a macOS agent):
nuget sources update -Name Local -Source "%BUILD_REPOSITORY_LOCALPATH%/LocalPackages"
Most helpful comment
Thanks for reporting this.
We recommend using Team Services Package Management instead of checking your packages into your source tree.
An alternate work around is to add the absolute path to the folder on the build agent via environment variable - e.g.
<add key="Local" value="%BUILD_SOURCESDIRECTORY%\LocalPackages" />
The environment variable will be resolved in the build, but not resolved on your local machine.