2
votes

I'm trying to get nuget package restore working in a solution that is looking for packages in the regular, public nuget feed and in a local feed located on a shared network drive.

What I've tried so far is enabling nuget package restore on the solution, then editing the Nuget.targets and changing the PackageSources variable, but that doesn't seem to work. Is this possible?

My Nuget.targets file looks like this for the package sources section:

<ItemGroup Condition=" '$(PackageSources)' == '' ">
    <!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
    <!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
    <PackageSource Include="https://nuget.org/api/v2/" />
    <PackageSource Include="\\mynetworkshare\Development\NugetPackages" />
</ItemGroup>

The error I get on build is "Unable to find version '1.0.0' of package 'MyCustomPackage'. I have verified that the nupkg exists at \\mynetworkshare\Development\NugetPackages\MyCustomPackage.1.0.0.nupkg.

3

3 Answers

3
votes

The fix for me was bhuvak's answer plus I had to rename some packages.

I had been creating symbols packages (named similar to MyCustomPackage.1.0.0.symbols.nupkg) and using those from my local package feed folder. However, package restore doesn't seem to pick those up. I had to rename them, removing the .symbols portion of the file name.

After I did that, package restore works great.

2
votes

Updating the sources in NuGet.targets should work. Make sure you have added both official NuGet source and local feed explicitly in the targets file. What error are you noticing ?

1
votes

We had a similar issue to @evan. We're using the CreateNewNuGetPackageFromProjectAfterEachBuild package to create our NuGet packages on a TFS 2013 build server. We have a local, share based package source and copy the nupkg files from the build output to this share. We found that builds that reference these packages fail because NuGet package restore fails to find the packages in the local source.

Running NuGet from the command line on the build server we get strange behaviour:

nuget.exe list <search-term-for-our-packages> -allversions

always succeeds and lists each version of our packages. However, when we go to a failed build's \src folder and run

nuget.exe restore .\oursolution.sln

we always get:

Unable to find version '1.0.6.341' of package 'our.package.name'.

I tried all sorts of things to resolve this, playing with nuget.config and swapping between versions of nuget.exe but the fix was simply to do with the naming of our nupkg files. By default CreateNewNuGetPackageFromProjectAfterEachBuild names the nupkg that it generates as the package Id plus the build configuration and target. E.g.

our.package.name.1.0.6.341.Release.AnyCPU.nupkg

With this file in our package source nuget list works but nuget restore fails. When I rename the package to

our.package.name.1.0.6.341.nupkg

then nuget list and nuget restore work as expected.

Our fix is simply to modify the config file of CreateNewNuGetPackageFromProjectAfterEachBuild to prevent it including the build configuration and target. But why does nuget restore depend on the package file name whereas nuget list doesn't?