0

UPDATE: Apparently providing too much pre-amble adds more confusion that clarity, so here's my question:

How do I add packages to a project from the local packages repository (i.e. not the central NuGet repository) when there are no references to them in the current solution and thus they do not show up as installed in the "Manage Package for Solutions" window.

Original with the background detail:

We use a local NuGet package folder that contains all the packages to be used by our projects. We do NOT want it to be arbitrarily updated or changed (i.e. no Installs of existing packages or restore's (if possible))

We've recently switched to VS2017 and are building our solutions and projects from scratch. We set up a NuGet.Config to point to the local packages folder. It works (as in we see new packages installed there if we test-install a package into a project from the NuGet central repository).

However, because the NuGet packages are currently not installed into any projects in the solution, NuGet reports (via Get-Package or the GUI) that there are no packages installed.

This seems to mean that we can't add the projects in the packages directory to the appropriate solutions without going to the central NuGet repository, despite their availability in the local package folder!

I'd prefer to see the package in the repository so that I can add them to their respective projects and have NuGet create the packages.config file for the project (using the new format).

Do I really have to re-install the packages from NuGet's central server just to add them to a project?

Installing from the central NuGet repository literally writes over the existing package in the local repository. More to the point, a few of our packages use versions that are no longer available on the NuGet repository.

Our current work-around is to editing the packages.config file by hand in one project in the solution, which makes the package visible in the "Manage Package for Solutions" window. We then can install the package in our actual target project by simply selecting the target project in the GUI (this performs the appropriate alterations on the target project's .csproj file). We then remove the hand-edited packages.config from the original project.

This is using NuGet 4.6 as installed by VS 2017.

Many thanks for any advice.

Tom West
  • 1,759
  • 2
  • 13
  • 20
  • Not sure I understand what your packages folder structure is compared with your projects. You have the .nupkg files in the same packages folder that would be used if you installed them in the project? If you do not want them local copied and extracted there you could use PackageReferences. However I do not think I understand what you are trying to do and what the problem is. – Matt Ward Aug 25 '18 at 14:44
  • We have a packages directory containing all the NuGet packages for all solutions in the company (which is committed to our source repository). This is the regular "packages" folder which includes the a directory for each package (and includes the .nupkg file somewhere in the folder for that package). We don't ever want the "packages" folder changed except by someone high level (we've had nightmare experiences of someone accidentally adding a new Fody package that blew up every solution). – Tom West Aug 26 '18 at 00:54
  • Sorry, I also can not understand what is your problem? Is this your question "We don't ever want the "packages" (**local package repository**) folder changed except by someone high level"? If yes, I am confused in the second to fifth paragraphs of the text. Are they related to your question or they are just other questions? Would you please modify your question with short description, if you have one more question, please separate them, don't let them cross, then you will get the better support :). – Leo Liu Aug 27 '18 at 03:16
  • I've added my single question at the top of the post. Admittedly clarity is not helped by the fact that 'install' can mean copying from central repository to local packages folder OR it can mean modifying a project file to use a package in the local packages folder. – Tom West Aug 27 '18 at 14:11

1 Answers1

4

How do I add packages to a project from the local packages repository (i.e. not the central NuGet repository) when there are no references to them in the current solution and thus they do not show up as installed in the "Manage Package for Solutions" window.

Not sure if I completely understand your problem correctly, if not, please let me know for free.

To resolve this issue, you can create a local feed for those packages, so that you can see those packages in the Manage Package for Solutions and add them to their respective projects and have NuGet create the packages.config file for the project even if you don't have them installed.

  • Add those packages .nupkg into your local repository folder (Including those versions that are no longer available on the NuGet repository).
  • Head into Visual Studio and open the NuGet Settings dialog via Tools > NuGet Package Manager > Package Manager Settings. Click the Package Sources tab within the settings dialog, followed by the plus icon in the top left to add a new package source.
  • Enter the Name and Source of your local repository. The name can be any string and will be the name displayed in the NuGet Package Manager within Visual Studio.

enter image description here

Now that you have added the local package source, you will be able to use your local repository from within Visual Studio in the usual way, either via the Console or via the Package Dialog, by selecting it from the Package Source menu:

enter image description here

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thank you very much. I think this solution is the best we can do. NuGet really, really wants to update everything from a central repository, and my attempt to not have it do so was definitely "fighting the tool". This suggestion is definitely keeping with the NuGet spirit and what we will adopt going forward. – Tom West Aug 28 '18 at 16:43