8

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?

Alex Sanséau
  • 8,250
  • 5
  • 20
  • 25
  • Please provide a more concrete description of what you were trying to accomplish and provide an example of the project file that doesn't behave as expected. – Martin Ullrich Apr 19 '18 at 10:44
  • @MartinUllrich, please take a new look when you have a moment, I've added 2 examples to make the question clearer. Thanks. – Alex Sanséau Apr 20 '18 at 08:34

3 Answers3

9

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.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • thanks for the link to the issue. I'll follow it with great interest. – Alex Sanséau Apr 20 '18 at 13:52
  • Thank you, however it does not work for: dotnet build and dotnet test, which still try to restore the packages without floating, which has a workaround to use the --no-restore argument, but it should also work without that argument imho. – rfcdejong Jan 21 '19 at 09:27
1

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • @LeoLiuMSFT, thanks for your response. 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. Please take a new look when you have a moment, I've added 2 examples to illustrate the question. – Alex Sanséau Apr 20 '18 at 08:38
  • @AlexSanséau, OK, I will check it later, and try to give the update. :) – Leo Liu Apr 20 '18 at 08:42
  • @AlexSanséau, I have test with a sample, got the same result as you. Then I found it is an open issue about nuget, https://github.com/NuGet/Home/issues/912. You can check my updated answer for details. – Leo Liu Apr 20 '18 at 09:44
  • @LeoLiuMSFT, thanks for finding reference of this issue on GitHub. I'll definitely track it, hoping that this will get resolved soon. – Alex Sanséau Apr 20 '18 at 13:45
0

The NuGet,version >5.6, floating version syntax allows for some pretty powerful version ranges, but it is likely that your scenario will be mostly satisfied by the following 3 floating versions:

<!-- Float everything! Latest version available including prerelease-->
<PackageReference Include="mypk" Version="*-*" />

<!-- Prefer latest 1.X version, include prerelease and stable -->
<PackageReference Include="mypk" Version="1.*-*" />

<!-- Prefer latest 1.0.X version, include prerelease and stable -->
<PackageReference Include="mypk" Version="1.0.*-*" />

Ref

M.Hassan
  • 10,282
  • 5
  • 65
  • 84