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?

有帮助吗?

解决方案 2

I finally got NuGetPowerTools to install after the advice from digitaltrust on http://blog.davidebbo.com

Although NuGetPowerTools solved my problem, it was overkill for what I wanted. It requires that you check in to version control a .nuget folder that it creates in your solution root. The folder contains NuGet.exe, and a couple of target files. I don't like this as I think version control is for source code, not tools.

I came up with the following solution.

  1. Save NuGet.exe to a folder on your local drive, both on dev and continuous integration machines. I chose C:\tools\nuget\
  2. Add that filepath to the Path Environment Variable in all environments
  3. On continuous integration machines, find %APPDATA%\NuGet\NuGet.Config and enter the following

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <packageSources>
        <add key="LocalRepositoryName" value="http://Domain/DataServices/Packages.svc/" /> 
    </packageSources> 
    

    You can add more than one entry to packageSources and NuGet will search them in the order that they appear

  4. The after build code from my question can now be amended to the following.

    <Target Name="BeforeBuild">
        <Exec Command="nuget install $(ProjectDir)packages.config 
        -o $(SolutionDir)packages" />
    </Target>
    

The end result of this is that whenever the approved repository location is changed, the config has to be changed in only one place rather than in every csproj file. Also, it is the continuous integration server administrators who determine that location, not the developers in their command line calls.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top