How can 'nuget restore' download pre-release packages?

Aaron Cunnington picture Aaron Cunnington · Jan 30, 2014 · Viewed 10k times · Source

We are faced with an issue in our build environment where we would like for our continuous integration builds to download the 'latest and greatest' NuGet packages that are marked as pre-release by appropriately appending the version number with -dev.

Whenever we run the command nuget restore, it fails to pick up any pre-release versions. I have looked over the documentation on the NuGet Versioning page but it rather inconveniently omits details on how to add prerelease ranges to the allowed versions it should download in the packages.config file.

Currently, the packages.config file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Foo" version="1.0.0" targetFramework="net35" />
</packages>

And we wish to be able for NuGet to at least be able to see and then to choose the latest version from a list like the following:

  • Foo.1.0.0-dev1401291727ef87505.nupkg
  • Foo.1.0.0-dev14012918064fdf488.nupkg

Unfortunately, no pre-release versions are seen, and only 'released' packages are used by the restore process. A typical error message when trying to download a pre-release only package would be:

Unable to find version '1.0.0' of package 'Foo'.

Is there some way that I can specify a range of versions that includes pre-release packages in the packages.config file? Or even from within the .nuspec file itself?

Many thanks in advance.

Answer

Matthew Skelton picture Matthew Skelton · Feb 6, 2014

There is no way AFAIK to specify to use pre-release packages within packages.config. Instead, use the -InstallPrerelease flag (PowerShell) or Prerelease flag (command-line nuget.exe) to specify that pre-release/beta packages should be installed in preference to stable packages.

Note that Foo.1.0.0-dev1234 is considered earlier than Foo.1.0.0, so if the the stable package exists (Foo.1.0.0) then any Foo.1.0.0-xxxx beta/pre-release packages will not be installed. In such a case, you'd need to up-rev the beta version to (say) Foo.1.0.1-devxxxx for it to be found as 'newer' than Foo.1.0.0.

See here for further details: How to publish nuget prerelease version package