title: Storing nuget packages in alternate location on build server
body: <p>When developing locally I have my Nuget packages installed in the default location (\packages within solution folder).</p>
  
  <p>I want have a different folder on my build server that acts as the repository path where I can download packages too, effectively giving me a local cache of packages which will persist across builds, not requiring all packages to be downloaded fresh every time build.</p>
  
  <p>On the CI server I drop a nuget.config file into the solution directory which specifies the location of the new packages folder:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;config&gt;
      &lt;!-- Specify repository path --&gt;
      &lt;add key="repositorypath" value="x:\nugetPackages" /&gt;
    &lt;/config&gt;
    &lt;activePackageSource&gt;
      &lt;add key="nuget.org" value="https://www.nuget.org/api/v2/" /&gt;
    &lt;/activePackageSource&gt;
    &lt;packageRestore&gt;
      &lt;add key="enabled" value="True" /&gt;
      &lt;add key="automatic" value="True" /&gt;
    &lt;/packageRestore&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>This part works fine and downloads packages to x:\nugetPackages\ but when I try to build the solution I get exceptions as the dlls are not found. This makes sense as the hintPath for the references is "..\packages\lib\lib.dll" whereas I want it to be on a different drive completely.</p>
  
  <p>My main msbuild task is just building the Solution file. To get this to work I've tried various options in my msbuild script, from:</p>
  
  <ul>
  <li>Specifying AssemblySearchPaths in BeforeResolveReferences task (as per <a href="http://www.beefycode.com/post/resolving-binary-references-in-msbuild.aspx" rel="noreferrer">http://www.beefycode.com/post/resolving-binary-references-in-msbuild.aspx</a>)</li>
  <li>Manually specifying AdditionalLibPaths and/or AssemblySearchPaths as a parameter when building the project.</li>
  <li>Specifying another "activePackageSource" element in the nuget.config file.</li>
  </ul>
  
  <p>All of the above result in lots of warnings similar to: <code>error CS0246: The type or namespace name 'HttpRequestMessage' could not be found (are you missing a using directive or an assembly reference?)</code></p>
  
  <p>I've managed to get it to work by altering the MSBuild script to:</p>
  
  <ol>
  <li>Restore nuget packages to 'cache' folder (e.g. x:\nugetPackages).</li>
  <li>Copy these packages over to the default location (..\packages).</li>
  <li>Build solution.</li>
  </ol>
  
  <p>This seems to be an overly long winded way of dealing with this, am I missing something obvious?  I've read a few blog posts where people are using XSLT to rewrite the 'hintPath' element for all project files in the solution - surely there's a better way of doing this?</p>