Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Jenkins aware of custom NuGet Package Source

Tags:

I've got a little issue regarding Jenkins and NuGet package restore.

What I'm trying to do is build solutions on jenkins (which works perfectly fine). I have enabled package restore for the solution, which generates the .nuget-folder containing NuGet.exe, NuGet.Config and NuGet.targets.

On Jenkins, I am pulblishing some projects as NuGet-packages in a private package source on our server. I am using those packages in other projects, which should be build on jenkins themselves.

VS knows about the private package source, it's configured in the global NuGet.Config-file (the one under AppData) and it is not disabled (by default).

Now, when I try to build a solution which needs a package from the private package source, the build fails, because jenkins doesn't know about it, and is therefore commiting an empty -source-parameter when restoring packages which is not beeing replaced as jenkins doesn't know about the custom source.

What I've tried so far

  1. I already know that adding the private source to the solutions NuGet.Config- or NuGet.Targets-file's Package-Source would solve the problem, but that would mean, i would have to do so for every solution I want to build using Jenkins.

  2. I have also played around a bit with the config-files in AppData and ProgramData by adding the source in to the package-source tags in the files and even making it the active-source, but that didn't help either

  3. of cource, commiting the packages would be a workaround, but thats not the desired outcome, as we'd like to ignore the packages in scm.

Basically, i'd like to know if there is a way to make Jenkins constantly aware of the private package source, or to manipulate the NuGet-installations on the developers maschines, so that they generate a NuGet.targets-file which contains the private package-source. An other possible fix would be a parameter for msbuild, which I'm not aware of.

Any help is greatly appreciated!

like image 989
nozzleman Avatar asked Aug 05 '14 13:08

nozzleman


People also ask

How do I add a source to a NuGet package?

To manage your package sources, select the Settings icon or select Tools > Options. In the Options window, expand the NuGet Package Manager node and select Package Sources. To add a source, select +, edit the Name, enter the URL or path in Source, and then select Update.

Where is NuGet config?

For NuGet 2.6 to 3. x, the computer-level config file on Windows was located in %ProgramData%\NuGet\Config[\{IDE}[\{Version}[\{SKU}]]]\NuGet.


2 Answers

To sum up (and extend) my comments:

Nuget package restore via msbuild is deprecated in current versions of Nuget (2.7 and higher)

We use a batch step in Jenkins

nuget.exe restore SOLUTIONTOBUILD.sln -source http://nugetserver...

and avoid thereby the problem that the Jenkins service runs in a different account and searches for the .config in a different place.

On the developer machines, the packages are restored by the Nuget-VS-Addin (and not by msbuild), so don't forget to undo the changes that the old Nuget-VS-Addin may have applied to your project-files.

More Information can be found in the Nuget-Docs

like image 199
frank koch Avatar answered Sep 19 '22 14:09

frank koch


Another solution to this problem is to add your custom NuGet.config and executable to a directory on the Jenkins server, and add a build step to run nuget using the custom config.

C:\nuget\nuget.exe update "%WORKSPACE%\Project.sln" -ConfigFile C:\nuget\NuGet.config 

A NuGet.config adding a custom package source would look something like this:

<?xml version="1.0" encoding="utf-8"?> <configuration>   <packageRestore>     <add key="enabled" value="True" />     <add key="automatic" value="True" />   </packageRestore>   <packageSources>     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />     <add key="nuget.org" value="https://www.nuget.org/api/v2/" />     <add key="My Custom Package Source" value="http://localhost/guestAuth/app/nuget/v1/FeedService.svc/" />   </packageSources>   <activePackageSource>     <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />   </activePackageSource> </configuration> 

The standalone nuget.exe can be downloaded here

This approach makes it easier to add custom feeds to all your jenkins jobs by changing the same config file.

like image 44
Fábio Junqueira Avatar answered Sep 20 '22 14:09

Fábio Junqueira