I'm creating a pre-release NuGet package as part of an Azure DevOps build, and pushing it to the internal Azure DevOps feed. This is working fine.
As part of the same pipeline, I want to use this newly-pushed package so that I can restore it and run some tests. I can't seem to find a way of getting the latest version to be restored.
In the project into which I want this to be restored, I've set the package reference to have a wildcard:
<ItemGroup>
<PackageReference Include="MyNewNuGetPackage" Version="0.*" />
</ItemGroup>
When packing, I'm using this step in my pipeline:
- task: DotNetCoreCLI@2
displayName: Pack
inputs:
command: pack
versioningScheme: byPrereleaseNumber
requestedMajorVersion: 0
requestedMinorVersion: 1
requestedPatchVersion: 0
packagesToPack: 'src/**/*.csproj'
packDestination: '$(Build.ArtifactStagingDirectory)'
This creates a package with a version number of MyNewNuGetPackage.0.1.0-CI-20211111-084008.nupkg
This is correctly pushed to my internal feed, but when I try and restore the packages for my target project, using this step:
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: 'MyTargetProject.csproj'
feedsToUse: 'select'
vstsFeed: 'my-local-feed-id'
Then I get this error:
(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
So the task can see that there's a pre-release version there, but I assume it's only looking for non-pre-release (i.e., stable) releases, given the error 'Unable to find a stable package'.
How do I do a NuGet restore as part of this build that restores the latest pre-release package?
CodePudding user response:
Try specifying the dependency version in the csproj file like this:
<ItemGroup>
<PackageReference Include="MyNewNuGetPackage" Version="0.*-*" />
</ItemGroup>
See this specification for more details.