This project is read-only.

-Safe and -IncludePrerelease don't behave correctly


We produce regularly different versions of packages and often we have an overlap between an RC and Beta phase for the same components.
We use the package prerelease function to tag the packages accordingly which makes it necessary to use the -IncludePrerelease flag when updating pakcages.

When this flag is used the -Safe flags seems to be ignored.

Say we have 1.14.2-RC9091 and 1.15.0-Beta1241 in the Nuget Repository.
In our solution we reference 1.14.2-RC9020 but we want to update to 1.14.2-RC9091.
To do so, we use the following powershell commandline:
update-package -Safe -IncludePrerelease

Nuget installs version 1.15.0-Beta1241 !!!!

file attachments


teajay wrote Jan 25, 2013 at 8:14 AM

Just found the culprit in VersionUtility.cs:

/// <summary>
    /// The safe range is defined as the highest build and revision for a given major and minor version
    /// </summary>
    public static IVersionSpec GetSafeRange(SemanticVersion version)
        return new VersionSpec
            IsMinInclusive = true,
            MinVersion = version,
            MaxVersion = new SemanticVersion(new Version(version.Version.Major, version.Version.Minor + 1))
Is version.Version.Minor + 1 realy correct here ?

teajay wrote Jan 25, 2013 at 9:08 AM

Forget my last comment ....

teajay wrote Jan 25, 2013 at 10:29 AM

Found the bug ... and here's a patch to fix it !

Could a fix for this make it into the next 2.2 release ?
This is really ugly !

dotnetjunky wrote Jan 25, 2013 at 9:03 PM

Thanks for the investigation. Would you mind sending a pull request for your fix, including unit tests?

We have already shipped 2.2, so we can only ship this fix in 2.3 release.

Meanwhile, there's an easy workaround. You can add the allowedVersions attribute to the package's entry in the packages.config file.

FilipDeVos wrote Jul 4, 2013 at 11:00 AM

I think the MaxVersion should be specified like this:
MaxVersion = new SemanticVersion(new Version(version.Version.Major, version.Version.Minor + 1, 0), "a")

UebeLt wrote Jan 31, 2014 at 9:20 AM

This still fails for me with NuGet version 2.8.50126.400.

The command is:
.nuget\NuGet.exe update -Safe -Source http://TeamCity/guestAuth/app/nuget/v1/FeedService.svc/ -Prerelease -Verbose -NonInteractive -FileConflictAction Overwrite -Id MyDriver -RepositoryPath packages MyTests.sln
with the following output:
Scanning for projects...
Found 1 project with a packages.config file. (MyTestProject)
Looking for installed packages in 'packages'.
Updating 'MyTestProject'...
Looking for updates for 'MyDriver'...
Updating 'MyDriver' from version '3.0.0' to '3.1.0-alpha-41' in project 'MyTestProject'.
Removing 'MyDriver 3.0.0' from MyTestProject.
Added file 'packages.config'.
Successfully removed 'MyDriver 3.0.0' from MyTestProject.
Adding 'MyDriver 3.1.0-alpha-41' to MyTestProject.
I actually want to update to version 3.0.1-rc-1 of MyDriver, which is present for sure.