2

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 ==?

aloisdg
  • 22,270
  • 6
  • 85
  • 105

2 Answers2

2

It's called the "Use exactly this version" constraint. It really should be part of the paket.dependencies reference but instead it is found in: https://fsprojects.github.io/Paket/nuget-dependencies.html

I'll try to explain it with an example. Imagine that you depend on packages A & B.

Both A and B depend on C but in their respective nuget package dependency declaration they specify that:

A depend on C version >= 1.2.3 but < 2.0

B depend on C version >= 2.0

In this situation paket will fail to find a common version of C that suits both A and B.

I've seen cases in some projects where there is a dependency to a package like A that claims it won't work with versions >= 2.0 of package C. However when actually tested, A works just fine with the highest version of C. Therefore a line to force paket to override the version constraint A have on C can be added:

nuget C == 2.0

Of course, the long term solution is to ask the maintainer of A to update their nuget dependency declaration.

8DH
  • 2,022
  • 23
  • 36
1

Paket is an Open Source project. Lets dig the source. The paket.dependencies file parse is available on GitHub. Here is the 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 given version will be used. This is a rough understanding, please and any thorough answer beside.

aloisdg
  • 22,270
  • 6
  • 85
  • 105