Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PackageReference Versioning Wildcard csproj

I have the following in my NetStandard Project

<ItemGroup>
<PackageReference Include="MyReference" Version="1.0.*" />
</ItemGroup>

When I change it to use the wildcard (instead of 1.0.1) I get an exclamation mark on the dependencies toggle, then the NuGet toggle and then of course the package itself.

When I check in, the CI build also fails on the other end, giving me

Unable to find package MyReference. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org

All of the above issues disappear when using the actual version with no wildcard (1.0.1), but I want to ensure that the .NET Core Restore Task, always restores to the latest package, and I was hoping a simple wildcard would do it.

NB - I am using my own private NuGet repository (Package Management Extension)

Please advise.

Why would using a wildcard fail during the CI build, indicating that it can't find the package?

So let's say I have project1 deployed to my own NuGet repository. Project2 has a dependency on Project1, which has been added as a NuGet package to Project2. Project1 package resides, without issue nor error in my own repository.

When I use the wildard and build locally, it works, and restores the latest version. When I check in the code changes (with wildcard left in the .csproj) - CI Build fails with the aforementioned error message.

like image 586
The_Chud Avatar asked Sep 14 '18 00:09

The_Chud


1 Answers

As per the official doc

When using the PackageReference format, NuGet also supports using a wildcard notation, *, for Major, Minor, Patch, and pre-release suffix parts of the number. Wildcards are not supported with the packages.config format.

For your question

Always specify a version or version range for package dependencies in project files, packages.config files, and .nuspec files. Without a version or version range, NuGet 2.8.x and earlier chooses the latest available package version when resolving a dependency, whereas NuGet 3.x and later chooses the lowest package version. Specifying a version or version range avoids this uncertainty.

like image 176
Jayendran Avatar answered Sep 20 '22 20:09

Jayendran