Thursday, November 8, 2012

Share Nuget packages between solutions part 2

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 :( 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:
    <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
        <!-- Windows specific commands -->
        <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
        <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
    I have added the following row:
  2. Change the arguments of the NewGetCommand from:
    <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
  3. To make the configuration more flexible we can change the PackagesDir definition to
    <PackagesDir Condition="'$(PackagesDir)' == ''">$(SolutionDir)..\First\packages</PackagesDir> 
    this will allow us to predefine the PackagesDir value in the .csproj.user files.
  4. To test this we can add the C:\ NugetConfig\First\Dummy\Dummy.csproj.user with the following content:
    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="">
    This will make the Nuget to get files in the C:\NugetConfig\packages folder.
And here is the code


  1. Is it possible that it didn't work because of the extra space before repositoryPath:

    <add key=" repositoryPath"

    Where is the NuGet.targets file you're editing? I thought it was a per-machine config file, so other people working on the same project would also have to edit their NuGet.targets file?

  2. Nope, I've tried it with and without the space (as in the release notes there is space) and I couldn't make it work.
    About the NuGet.targets file, it is located in ".nuget" subfolder in the solution folder.

  3. What i do not realize is in truth how you are not really much more well-liked than you may be now. You are so intelligent. You realize therefore significantly on the subject of this topic, produced me in my opinion believe it from numerous numerous angles. Check telephone answering service for best Telephone Service.

  4. So many years later, setting the repository path seem to work just fine.