5

There are some situations where I have no internet connection and so I am forced to work offline. Usually it would look like this: I get connected, do a checkout from source control server, and move out of office. The NuGet packages stay on the server, because I have enabled Package Restore and should have opened Visual Studio and fired a build at least once, to download them.

Before using NuGet we had the package management integrated using SVN externals. The required assemblies were automatically downloaded during checkout. But this system has some limitations, I'd like to get rid off.

The prefered way to use Package Restore would be to execute it on checkout or update. Is there a way doing so, using hooks for SVN (TortoiseSVN) or GIT (TortoiseGIT, Github for Windows) as version control system?

  • Did you ever get to solve this? (and while I'm at it) – Martin Ba Feb 25 '15 at 10:46
  • Not really. At the moment I'm planning to do an automatic background synchronization – dwonisch Feb 26 '15 at 8:31
1

For Git you can use a post-commit hook. To do so, you would create an executable script named post-checkout in the .git/hooks folder in the repository. In the file, you would put the following:

/path/to/nuget.exe restore /path/to/solutionfile

On Linux/Mac, do the following instead:

#/bin/sh
mono /path/to/nuget.exe restore /path/to/solutionfile

and it should work.

This will be automatically executed after the repository has been checked out. To see more info about the nuget restore command, see here.

0

The following is not a direct answer to your question, but might solve the issue that led to the question.

We have a single directory in source control where we put all the .nupkg used by our projects. (Being a relatively small team, this directory is not too cluttered.)

We link this directory in source control to project directories, in your case this would be a SVN external.

Additionally, we put a Nuget.Config file in the same directory as the .sln file where we add the checked-out directory with the packages as package source:

<!-- ... -->
<packageSources>
  <add key="LocalPackages" value="relative/path/to/checked/out/directory" />
  <!-- ... -->

To make sure package restore will always use this directory, one can add

<activePackageSource>
  <add key="LocalPackages" value="relative/path/to/checked/out/directory" />
</activePackageSource>

but this has the drawback that searching/installing new packages from nuget.org from within a project using such a NuGet.Config requires some more clicks.

As a result, checking out a project will check out all required NuGet packages (and some more, what could be a con), and NuGet/Visual Studio will happily restore them without a network connection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.