How to include pre-release packages with MSBuild restore target

自闭症网瘾萝莉.ら 提交于 2021-01-03 05:34:24

问题


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?


回答1:


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.




回答2:


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'

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.



来源:https://stackoverflow.com/questions/49917703/how-to-include-pre-release-packages-with-msbuild-restore-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!