NuGet VS2012 multiple solutions – project with only one package folder

As I am currently using some nuget projects which are are altogether about 600MB I wanndered how to set it up to have only one folder of them for every project (in different solutions). I found a way, but it is somehow tricky. Although itWorks!

As the note in information about [NuGetPackageFolderOverride] project says.

There may be dragons. You have been warned!

I am currently using Visual Studio 2012. Though they will be downloaded again for each new project, but you delete them afterwards.

  1. Create first project i.e [firstProject]
  2. Install nuget if it is not already installed
    http://docs.nuget.org/docs/start-here/installing-nuget
  3. Install your package i.e via PowerShell:
    Menu [TOOLS -> NuGet Package Manager -> Package Manager Console]
    $ Install-Package SharpOVR -Version 0.4.2
  4. Let it download the packages
    – It will emerge in [packages] directory next to the project file [firstProject.sln]
  5. Install nuget package for overriding nuget package folder (if you know what I mean)
    $ Install-Package NuGetPackageFolderOverride
  6. Create the folder in the new path.
    – i.e one step up the directory tree: [../_packages/]
  7. Configure the relative path to new package directory via PowerShell
    $ Install-NuGetPackageFolderOverride "../_packages/"
  8. Turn [Visual Studio] off
  9. Move the package folders from [packages] to new destination [_packages]
    – move all but the package [NuGetPackageFolderOverride] folder!
  10. Create new project and repeat the action?
    1. did not tried yet – I copied the first one
  11. Copy the [firstProject] files to another destination folder [secondProject]
    – It should be already without packages in [packages] folder
    – There may be a file [repositories.config] in the [packages] folder
    1. Delete file [secondProject/nuget.config] MANUALLY
      – It is quicker manually – you could use command:
      $ Remove-NuGetPackageFolderOverride

      Although you would have to restart the [Visual Studio] afterwards to have it show you the [Restore] button.
      – So just delete it manually

    2. Open the [secondProject]
      – If you try to build the project it may not see the packages in its default directory [secondProject/packages]
      Error 1 This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\SharpDX.2.6.2\build\SharpDX.targets. B:\__DIP\dev\SharpOVR\2015_01_25 2- wiggle 2\RiftGame\RiftGame.csproj 88 5 RiftGame
    3. Go to [Package Manager Console] and click [Restore]
      – Let it download the packages once again
    4. Configure the folder overide once again:
      $ Install-NuGetPackageFolderOverride "../_packages/"
    5. Build the solution
      – This is needed step!
      – It should build ok – as it builds using [secondProject/packages] packages.
    6. Turn off [Visual Studio]
    7. Kill Process [MSBuild.exe] via [Windows Task Manager] if it is running
      – If you do not kill it, you will have to after trying to delete in the next step as there will be file from one of the folders opened in it.
    8. Delete all [package folders] but the [NuGetPackageFolderOverride] folder from [secondProject/packages]
      – There may be a file [repositories.config] in the [packages] folder
    9. Open [secondProject] again
    10. It should build successfully using packages from [../packages/] folder

 

Hope it helped!
Consider keeping me awake with more coffee please 😉

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *