Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include pre-release packages with MSBuild restore target

This question is specific to MSBuild 15.1+ (Visual Studio 2017) and to PackageReference, which is the new way Nuget is fully integrated within MSBuild.

In my continuous integration script, I've got something like:

MSBuild.exe /t:Restore MySolution.sln /p:RestoreConfigFile=NuGet.config

One of the csproj file contains:

<PackageReference Include="MyPackageA">
    <Version>1.2.*</Version>
</PackageReference>

MyPackageA is an internal package and I would like nuget to resolve the reference to the latest version available, including pre-release version.

Let's take 2 examples:

Example #1

Packages available are:

  • MyPackageA version 1.2.7-dev1
  • MyPackageA version 1.2.7-dev2
  • MyPackageA version 1.2.7-dev3
  • MyPackageA version 1.2.8

I would like nuget to resolve the dependency and pick up MyPackageA version 1.2.8.

Example #2

Packages available are:

  • MyPackageA version 1.2.7-dev1
  • MyPackageA version 1.2.7-dev2
  • MyPackageA version 1.2.7-dev3
  • MyPackageA version 1.2.8
  • MyPackageA version 1.2.9-dev1
  • MyPackageA version 1.2.9-dev2

I would like nuget to resolve the dependency and pick up MyPackageA version 1.2.9-dev2.

However, it would only resolve to version 1.2.8 (the stable release) in both examples.

Is there a way to tell MSBuild or Nuget to include pre-release packages?

like image 620
Alex Sanséau Avatar asked Apr 19 '18 09:04

Alex Sanséau


2 Answers

At the moment, prerelease versions cannot be used together with floating versions.

You can use

<PackageReference Include="mypk" Version="1.0.*" />

OR

<PackageReference Include="mypk" Version="1.0.1-*" />

But not 1.0.*-*.

See this GitHub issue where this feature request is tracked.

like image 115
Martin Ullrich Avatar answered Nov 15 '22 07:11

Martin Ullrich


How to include pre-release packages with MSBuild restore target

AFAIK, there is no such option -IncludePrerelease for nuget restore, you can check the Options for restore command. And MSBuild restore also does not have this option, MSBuild restore target.

This option is used for nuget Install, Update.

As a test, I added the option -IncludePrerelease or PreRelease to the command line nuget restore, then I got the error message:

Unknown option: '-IncludePrerelease'

enter image description here

Besides, when we restore nuget package with nuget.exe restoe or MSBuild.exe /t:Restore, nuget will downloads and installs any packages missing from the packages folder based on the package list in the packages.config and PackageReference, the version information is indicated in the those file, like:

<package id="ExamplePackage" version="6.1.0" targetFramework="net45"/>

and

<PackageReference Include="ExamplePackage" Version="6.1" />

NuGet will download the corresponding version of the package, so we do not need give the option -IncludePrerelease.

Update:

I should have mentioned my reference includes a wildcard and I would like that wildcard to resolve to the latest version, including a pre-release version if it's the latest.

Indeed, this is a issue about restore pre-release packages for PackageReference:

https://github.com/NuGet/Home/issues/912

You can track this thread to get the latest status for this issue, and NuGet team already set this issue as pri 0, and try to resolve this issue ASAP.

Hope this helps.

like image 26
Leo Liu-MSFT Avatar answered Nov 15 '22 07:11

Leo Liu-MSFT