49
votes

I have two repositories, and I need compiled libraries from one repository in the other. I don't want to manually check repo1 for updated libraries, and copy/commit to repo2, because that is stupid. I've got repo1 building NuGet packages on each build of the necessary libraries, and publishing them to an internal NuGet server. Projects in repo2 can then reference these NuGet packages, and everything is (almost) working.

The one last hurdle to this is automatically updating the NuGet packages in repo2's projects. Since I don't know when the libraries in repo1 will get updated (and I shouldn't have to), I would like some sort of build event on the projects in repo2 that will automatically update the NuGet packages. I currently just have a pre-build event doing it, but since packages.config files contain the version number of the installed package, I keep getting modified files in repo2 (the packages.config files get updated).

So my question is: what's a good way to automatically upgrade NuGet packages without mucking up my repo2 VCS? ScottGu says Here (in comments) that it's possible to hook package upgrades up to CI builds, but he doesn't specify how and my current solution is messy. Is there a built in way that I'm missing? Or any better work-arounds?

3
Be careful. The libraries might change and break your software. blog.heroku.com/archives/2011/6/28/…Colonel Panic
That's what our automated test suite is for :)themilkyninja
@themilkyninja did you ever get a solution in place? I'm facing the exact same issue.stevebot
Nope. We ended up skipping NuGet all together and doing it manually. However we're up to 4 different dependencies now, so we're going to set up all the NuGet stuff again and just manually build packages when things change.themilkyninja
So what if... in one of the build steps there is a script to parse the version from a package feed (like this) and then modify your corresponding package version in package.config?Bemn

3 Answers

3
votes

You could probably leverage the NuGet Package Restore feature (a bit of info here : http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages)

At project build, it calls "nuget.exe -install" to reinstall the packages from packages.config. I haven't tried it but you could add a Update command to the nuget.targets file in the same way. (You'd have to call both nuget.exe update and the existing nuget.exe install).

0
votes

This explains how to do it via MSBuild

http://netitude.bc3tech.net/2014/11/28/auto-update-your-nuget-packages-at-build-time/

<Target Name="UpdatePackages" DependsOnTargets="CheckPrerequisites">
   <Exec Command="$(UpdateCommand)"
      Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

   <Exec Command="$(UpdateCommand)"
      LogStandardErrorAsError="true"
      Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>


<!-- Commands -->
<UpdateCommand>$(NuGetCommand) update "$(PackagesConfig)" -source "$(PackageSources)" -id AutoUpdater $(NonInteractiveSwitch)</UpdateCommand>
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)"  $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>

<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
    RestorePackages;
    UpdatePackages;
    $(BuildDependsOn);
</BuildDependsOn>
-1
votes

You can modify your .cspoj file to execute a "BeforeBuild" target like this :

<Target Name="BeforeBuild">
  <Exec Command="&quot;$(SolutionDir).nuget\NuGet&quot; update &quot;$(ProjectDir)packages.config&quot; -Id your.package.id" />
</Target>

Note that : u'll need to have the "Nuget.exe" in ur solution directory