title: Cannot automatically update a NuGet package to the latest version during build
body: <p>We have two separate .NET solutions:</p>
  
  <ul>
  <li>Running a build for the first solution produces our end product: a bunch of DLLs. These DLLs are delivered to our customers via a NuGet package.</li>
  <li>The second solution serves as a product-test solution: the NuGet package is installed to it, and it is built and executed - thus it makes use of our product exactly the same way as our customers would do.</li>
  </ul>
  
  <p>The challenge here is that there should be a way our latest NuGet package gets installed automatically to the product-test solution, preferably during the build of this product-test solution.</p>
  
  <p>Based on the ideas from <a href="https://stackoverflow.com/questions/9794907/how-to-automatically-update-nuget-packages-to-latest-available-version">a similar question</a>, I got this far with configuring the product-test solution:</p>
  
  <ul>
  <li>First I enabled NuGet Package Restore. This lets me get rid of the "packages" directory completely from VCS since the package with the version defined in packages.config file would be downloaded automatically by NuGet before build.</li>
  <li>Then I added the following pre-build event in Visual Studio: <code>$(SolutionDir).nuget\nuget update -prerelease $(ProjectDir)packages.config</code>. This lets me pull in the latest version of our NuGet package during build.</li>
  </ul>
  
  <p>I currently use the above scenario to run local builds using Visual Studio and unattended builds using TeamCity. The solution seems to work for both scenarios on the first sight, but actually <strong>it does not produce the expected result</strong>: when the product-test solution is built, in the <code>bin</code> directory I don't get the latest version of the DLLs, only the latest-1 version.</p>
  
  <p>The problem is that although the <code>nuget update</code> command updates everything as expected, including the <code>packages.config</code> and the <code>.csproj</code> file, their <strong>new content</strong> is not picked up by the build, therefore - as my guess goes - the <strong>HintPath</strong> settings from the <code>.csproj</code> file still reflect a "before build" state, therefore old DLLs are copied to the <code>bin</code> directory. I assume the <code>.csproj</code> file is processed only once: before the pre-build event is triggered, and the changes made by the pre-build event are ignored until the next build.</p>
  
  <p>I considered the following solutions:</p>
  
  <ul>
  <li>Apparently pre-build is not "pre" enough. If there was an even earlier point I could insert the <code>nuget update</code> command, my above solution would probably work.</li>
  <li>I read that I could override the HintPath-s in the .csproj file by defining a ReferencePath. But I doubt I could easily figure out the right path or I could set it early enough so the build picks it up.</li>
  <li>As a workaround I could run the builds twice: duplicate the build step for the product-test solution in TeamCity and I could always build the solution twice locally in Visual Studio.</li>
  </ul>
  
  <p>Has someone figured out how to automatically update a NuGet package to the latest version during build?</p>