Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding private Nuget package feeds to Visual Studio Online

I have a private NuGet package feed running, which I use to share certain functions and extensions between my projects. It works great in Visual Studio, but lately I've started setting up a continuous integration build for one of my projects on Visual Studio Online, and it seems that VSO can't see my private feed.

I'm using the new package restore method - the one that involves setting the "Allow NuGet to download missing packages" checkbox in the VS options. I'm not using the "Enable NuGet Package Restore" option in the solution context menu, because this is actually the old way of doing it and causes problems elsewhere.

I'm also not doing anything that modifies my project files; I'm using a custom build definition (using the XAML Workflow stuff) so that I can apply it to any of my projects by just picking it from the "Build process template" dropdown under the build definition editor. I'm doing it this way because I'm adding a variety of other steps including some post-build scripts to facilitate automated deployment to a hosting server; some of these steps are a little complex, so keeping them in the build process means I only have to set them up once.

So, without using the old context-menu solution that places nuget.exe into the solution folder, and without messing with the project itself, how can I get VSO's build to restore packages from my private feed?

The build workflow template has an activity "NuGetRestore", which can take commandline arguments. I've added the following:

"-source https://www.nuget.org/api/v2/ http://www.example.com/nuget"

but that doesn't seem to make a difference. This activity also has a field to "specify the solutions that need their NuGet packages restored", and I've just set that to the ProjectsToBuild variable which is set when you define the build. I'm not getting any errors from nuget.exe (at least, none that I can see), but the build fails. Interestingly, it says that the relevant namespaces don't exist, and not that the references can't be resolved. Any ideas?

like image 731
anaximander Avatar asked Jul 13 '14 13:07

anaximander


1 Answers

I believe what you need to do is add a solution level NuGet.config file. The NuGet config files are chained much like web.config. You can find documentation here

NuGet first loads NuGet.config from the default location, then loads any file named NuGet.config starting from the root of the current drive and ending in the current directory.

It will look something similar to this:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageRestore>
        <!-- Allow NuGet to download missing packages -->
        <add key="enabled" value="True" />
        <!-- Automatically check for missing packages during build in Visual Studio -->
        <add key="automatic" value="True" />
    </packageRestore>
    <packageSources>
        <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
        <add key="PrivateNugetName" value="http://your.nuget.server.com/nuget" />
    </packageSources>
    <disabledPackageSources />
    <activePackageSource>
        <add key="All" value="(Aggregate source)" />
    </activePackageSource>
</configuration>
like image 71
Jared Avatar answered Oct 14 '22 09:10

Jared