Click here to Skip to main content
Click here to Skip to main content
Go to top

Share Nuget packages between solutions: Part 2

, 6 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Share Nuget packages between solutions.

Let's see how we can fix the problem explained here. According to the latest release notes by now you should be able to change the packages folder by adding this setting in the Nuget.config file:

    <add key="repositoryPath" value="C:\myteam\teampackages"></add>

However unfortunately I couldn't make this work Frown | <img src= src="" /> So I found a workaround. I want to make the Second.sln use the package folder of First.sln. So I have made the following changes to the NuGet.targets file.

  1. I this section:
  2. <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
        <!-- Windows specific commands -->
        <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>

    I have added the following row:

  3. Change the arguments of the NewGetCommand from:
  4. <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source 
       "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir)</RestoreCommand>


    <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source 
       "$(PackageSources)" -o "$(PackagesDir)" $(RequireConsentSwitch) 
       -solutionDir "$(SolutionDir)</RestoreCommand>

    I have added -o "$(PackagesDir)" which should make the packages to be downloaded to the PackagesDir folder.

  5. To make the configuration more flexible we can change the PackagesDir definition to:
  6. <PackagesDir Condition="'$(PackagesDir)' 
      == ''">$(SolutionDir)..\First\packages</PackagesDir>

    This will allow us to predefine the PackagesDir value in the .csproj.user files.

  7. To test this we can add the C:\ NugetConfig\First\Dummy\Dummy.csproj.user with the following content:
  8. <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" 

    This will make the Nuget to get files in the C:\NugetConfig\packages folder.

And here is the code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vasil Trifonov
Software Developer (Senior) Telerik
Bulgaria Bulgaria
No Biography provided
Follow on   Twitter   Google+

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 6 Dec 2012
Article Copyright 2012 by Vasil Trifonov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid