0
votes

Restore from global nuget-repository

I have this packages.config-file:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="jQuery" version="3.1.1" targetFramework="net46" />
  <package id="NLog" version="4.3.10" targetFramework="net46" />
</packages>

And with this command I can restore nuget-packages, which are listed in above packages.config:

nuget restore packages.config -PackagesDirectory NuGetPackages -NoCache

This works nicely.

All the files for this example can be found here: https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_global_nuget_repository

Restore from local nuget-repository

In my company we have to use a repository, which is located on a network share. And we are not allowed to do package restore from the standard global nuget-repository.

For demonstration-purposes let's assume the local package-repository is in directory NuGetPackagesSource and this is its content:

-NuGetPackagesSource
 |-jquery
    |-3.1.1
      |-jquery.3.1.1.nupkg
      |-jquery.3.1.1.nupkg.sha512
      |-jquery.nuspec
 |-nlog.4.3.10.nupkg

With this NuGet.Config we make sure that the local package-repository is used instead of the global one:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <disabledPackageSources>
    <add key="nuget.org" value="true" />
  </disabledPackageSources>
  <packageSources>    
    <add key="my" value="NuGetPackagesSource" />
  </packageSources>
</configuration>

Following makes a restore from local directory NuGetPackagesSource:

nuget restore packages.config -ConfigFile NuGet.config -PackagesDirectory NuGetPackages -NoCache

Unfortunately following errors occur:

WARNING: Unable to find version '3.1.1' of package 'jQuery'. C:\software_download\nuget\NuGetPackagesSource: Package 'jQuery.3.1.1' is not found on source 'C:\software_download\nuget\NuGetPackagesSource'.

Adding package 'NLog.4.3.10' to folder 'C:\software_download\nuget\NuGetPackages' Added package 'NLog.4.3.10' to folder 'C:\software_download\nuget\NuGetPackages'

Errors in packages.config projects Unable to find version '3.1.1' of package 'jQuery'. C:\software_download\nuget\NuGetPackagesSource: Package 'jQuery.3.1.1' is not found on source 'C:\software_download\nuget\NuGetPackagesSource'.

As you can see from the error-message package jquery cannot be restored. But package NLog is successfully restored. I have no explanation of this behaviour as both packages jquery and NLog are in the local package-repository.

All the files for this example can be found here: https://github.com/ezeh2/nuget_restore_examples/tree/master/nuget_with_local_nuget_repository

1

1 Answers

0
votes

Take a closer look at your package repository. The NLog-package is directly underneath NuGetPackagesSource whereas jquery-package is in path jquery/3.1.1/jquery.3.1.1.nupkg. You use a different folder structures for packages NLog and Jquery. If nuget sees a nupkg-file directly underneath NuGetPackagesSource it assumes that all nupkg-file are on the same level and it does not search in folders underneath NuGetPackagesSource. This is why get error Unable to find version '3.1.1' of package 'jQuery', even though jquery-package is there.

How to fix this issue

Get rid of your NuGetPackagesSource-folder and build it newly from scratch with nuget install like this:

nuget install jQuery -Version 3.3.1 -OutputDirectory NuGetPackagesSource

nuget install NLog -Version 4.3.10 -OutputDirectory NuGetPackagesSource

Alternative solution

Put all your nupkg-files directly under NuGetPackagesSource and don't use nuget install at all. But this only works for simple packages without additional folders. Unfortunately this cannot be done with NLog and JQuery.