如何将预发布 NuGet 包的最新版本还原为 Azure DevOps 构建的一部分

How to restore the latest version of a pre-release NuGet package as part of an Azure DevOps build

我正在创建一个预发布的 NuGet 包作为 Azure DevOps 构建的一部分,并将其推送到内部 Azure DevOps 源。这工作正常。

作为同一管道的一部分,我想使用这个新推送的包,以便我可以恢复它和 运行 一些测试。我似乎找不到恢复最新版本的方法。

在我希望将其还原到的项目中,我已将包引用设置为具有通配符:

<ItemGroup>
    <PackageReference Include="MyNewNuGetPackage" Version="0.*" />
</ItemGroup>

打包时,我在我的管道中使用了这个步骤:

- task: DotNetCoreCLI@2
  displayName: Pack
  inputs:
    command: pack
    versioningScheme: byPrereleaseNumber
    requestedMajorVersion: 0
    requestedMinorVersion: 1
    requestedPatchVersion: 0
    packagesToPack: 'src/**/*.csproj'
    packDestination: '$(Build.ArtifactStagingDirectory)'

这将创建一个版本号为 MyNewNuGetPackage.0.1.0-CI-20211111-084008.nupkg

的包

这已正确推送到我的内部提要,但是当我尝试为我的目标项目恢复包时,使用以下步骤:

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: 'MyTargetProject.csproj'
    feedsToUse: 'select'
    vstsFeed: 'my-local-feed-id'

然后我得到这个错误:

(Restore target) ->

/home/vsts/work/1/s/MyTargetProject.csproj : error NU1103: Unable to find a stable package MyNewNuGetPackage with version (>= 0.0.0)

/home/vsts/work/1/s/MyTargetProject.csproj : error NU1103: - Found 2 version(s) in feed-my-local-feed-id [ Nearest version: 0.1.0-CI-20211111-084008 ]

/home/vsts/work/1/s/MyTargetProject.csproj : error NU1103: - Found 0 version(s) in NuGetOrg

所以任务可以看到那里有一个预发布版本,但我假设它只是在寻找非预发布(即稳定)版本,因为错误 'Unable to find a stable package'.

作为此构建的一部分,我如何执行 NuGet 恢复以恢复最新的预发布包?

尝试像这样在 csproj 文件中指定依赖版本:

<ItemGroup>
    <PackageReference Include="MyNewNuGetPackage" Version="0.*-*" />
</ItemGroup>

有关详细信息,请参阅 this specification