fsprojects / Paket

A dependency manager for .NET with support for NuGet packages and Git repositories.
https://fsprojects.github.io/Paket/
MIT License
2.02k stars 520 forks source link

In a paket.dependencies file, what is the meaning of the operator `==`? #3596

Open aloisdg opened 5 years ago

aloisdg commented 5 years ago

Hello,

If issues are not the right way to ask about this, feel free to close it.

In a project's paket.dependencies file, I found thoses lines:

nuget Microsoft.AspNet.Mvc == 5.2.6
nuget Microsoft.AspNet.Razor == 3.2.6
nuget Microsoft.AspNet.WebPages == 3.2.6

I checked the official documentation without success. My guess would be that == could fix a version number but to achieve this we can directly write nuget Microsoft.AspNet.Mvc 5.2.6.

What is the meaning of the operator ==?

note that I also posted this as a question on Stack Overflow

aloisdg commented 5 years ago

Paket is an Open Source project. Lets dig the source. I found this logic:

match splitVersion text with
    | "==", version :: rest -> 
        let v = SemVer.Parse version
        VersionRequirement(VersionRange.OverrideAll v,parsePrerelease [v] rest)
    | ">=", version :: rest -> 
        let v = SemVer.Parse version
        VersionRequirement(VersionRange.Minimum v,parsePrerelease [v] rest)
    | ">", version :: rest -> 
        let v = SemVer.Parse version
        VersionRequirement(VersionRange.GreaterThan v,parsePrerelease [v] rest)
    | "<", version :: rest -> 
        let v = SemVer.Parse version
        VersionRequirement(VersionRange.LessThan v,parsePrerelease [v] rest)
    | "<=", version :: rest -> 
        let v = SemVer.Parse version
        VersionRequirement(VersionRange.Maximum v,parsePrerelease [v] rest)
    | "~>", minimum :: rest -> 
        let v1 = SemVer.Parse minimum
        VersionRequirement(VersionRange.Between(minimum,twiddle v1),parsePrerelease [v1] rest)
    | _, version :: rest -> 
        let v = SemVer.Parse version
        VersionRequirement(VersionRange.Specific v,parsePrerelease [v] rest)
| _ -> failwithf "could not parse version range \"%s\"" text

source

So == will set the VersionRange to OverrideAll. This will have an impact on IsGlobalOverride.

member x.IsGlobalOverride =
    match x with
   | OverrideAll _ -> true
   | _ -> false

source

To conclude == will override the package at the given version, when without, the current package at the givern version will be used. This is a rough understanding, please and any thorough answer beside.

Did I get it?

matthid commented 5 years ago

The general logic as I recall it is that == can be used to "force" solve conflicts. So usually they are the same but if one package B depends on A == 1.0 and you have B in your packages.dependencies paket will always resolve A as 1.0. When you put A 2.0 in your paket dependencies then paket will tell you that you have a conflict in your resolution as B needs A == 1.0.

If you put A == 2.0 in your paket.dependencies paket will assume you know what you are doing and ignore that conflict and resolve B and A with 2.0.

So in general don't use == until you clearly are trying to resolve a conflict manually and you know what you are doing. This is usually required:

Does that sound reasonable?