How to configure where NuGet.exe Command Tool line looks for packages

Daniel Dyson picture Daniel Dyson · Sep 22, 2011 · Viewed 11.9k times · Source

We have successfully set up a couple of local package repositories using the NuGet.Server package and hosted them on a local IIS webserver. We are able to connect from the Package Manager and install no problem. So these are working fine.

In order for us not to have to check in our packages folder we have included the following command line in each project file that includes NuGet references. This works, if the NuGet.exe is in the path on the CI build agent.

However, I would like to move the source configuration form the command line in every project file and put it in just one place, preferably where other pesky developers can't change it ;)

<Target Name="BeforeBuild">
    <Exec Command="nuget install $(ProjectDir)packages.config -s 
       http://domain:80/DataServices/Packages.svc/;
        http://domain:81/DataServices/Packages.svc/ 
       -o $(SolutionDir)packages" />
</Target>

Is there a better way?

Answer

Xavier Decoster picture Xavier Decoster · Sep 22, 2011

Yes there is ;-) Take a look at NuGetPowerTools. After running Install-Package NuGetPowerTools, it adds a .nuget folder to your $(SolutionDir) containing nuget.exe, nuget msbuild targets and settings (which you will need to check in).

After that, you simply run Enable-PackageRestore and it sets up msbuild targets into your visual studio project files which will make sure that packages will be fetched in a prebuild step, even on your build server, without checking in any packages. (don't forget to check in the .nuget folder though!).

This way, you simply manage the nuget package sources in a nuget msbuild settings file (in the .nuget folder) central to your solution, instead of in each project.

Cheers, Xavier