Package Management with NuGet

Although we recommend using Protobuild’s package management system, there are many package binaries and libraries available through NuGet.

Protobuild supports using NuGet packages with Protobuild projects, with support for package URLs of the form https-nuget://repository.org/|PackageName@PackageVersion.

Warning

NuGet does not offer proper seperation of platforms for binaries. You may find that installed NuGet packages work when targeting Windows, but fail when targeting other desktop or mobile platforms. These will most often manifest themselves as runtime failures or crashes (especially when running under Mono where assumed APIs may not be available).

Also be aware that (as of writing), Portable Class Libraries do not work on Mono under Linux. As such, even if the NuGet package provides a PCL version, it may not work on all platforms.

We highly recommend you ensure that the NuGet packages you have selected work on other platforms as early in the development process as possible.

Adding NuGet packages

You can add a NuGet package with the following command:

$ Protobuild.exe --add <URI>

You’ll need to know the repository URL, package name and package version that you want to add. For example, to add the Ninject package from nuget.org at version 3.2.2.0, you would use the following command:

$ Protobuild.exe --add "https-nuget://www.nuget.org/api/v2/|Ninject@3.2.2.0"

Note

You will need to quote the URL as it contains a pipe character for seperating the URL and package name. This is because on most systems, the pipe character is used to pipe one command into another.

Referencing NuGet packages

With Protobuild’s support for NuGet packages, you can reference a NuGet package like any other. In the project definition file which you want to reference the NuGet package in, add it to the References section, like so:

<?xml version="1.0" encoding="utf-8"?>
<Project Name="MyApplication" Path="MyApplication" Type="App">
  <References>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="Ninject" />
  </References>
  <Files>
    <Compile Include="Program.cs" />
  </Files>
</Project>

The reference name is the same as the package name you provided during --add.

Note

NuGet packages imported through this mechanism always have a single external project available for reference, even if the package has multiple DLLs. When a NuGet package contains multiple DLLs, the external project reference will add a reference to all of them.

Re-pushing packages to a Protobuild package repository

If you want to re-push a NuGet package (or any kind of supported binary package) back to a Protobuild repository, you can do so with the repush command, like so:

$ Protobuild.exe --repush <apikey> <source_url> <dest_url> <git_hash> <platform> <branch>

For example, to re-push a copy of Moq from NuGet to the Protobuild index, you would use a command like this:

$ Protobuild.exe --repush <apikey> "https-nuget://www.nuget.org/api/v2/|Moq@4.2.1502.911" http://protobuild.org/nuget/Moq hash:4.2.1502.911 Windows 4.2

This is useful if you are running your own Protobuild package repository, and want to ensure the packages continue to be available even if the original repository is offline.