Paket


Dependency Groups

Groups allow for better organization of dependencies and also enable easier conflict resolution. Let's consider a small example:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
source https://nuget.org/api/v2

nuget Newtonsoft.Json
nuget UnionArgParser
nuget FSharp.Core

github forki/FsUnit FsUnit.fs
github fsharp/FAKE src/app/FakeLib/Globbing/Globbing.fs
github fsprojects/Chessie src/Chessie/ErrorHandling.fs

group Build

    source https://nuget.org/api/v2

    nuget FAKE
    nuget FSharp.Formatting
    nuget ILRepack

    github fsharp/FAKE modules/Octokit/Octokit.fsx

group Test

    source https://nuget.org/api/v2

    nuget NUnit.Runners
    nuget NUnit

As you can see we have 3 different groups in the paket.dependencies file. The first one is the default group (internally called "Main") and the other two groups contain dependencies that are used for Build and Test.

Notice the indentation in groups is optional.

After paket install the generated paket.lock file looks like the following:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
NUGET
  remote: https://nuget.org/api/v2
    FSharp.Core (4.0.0.1)
    Newtonsoft.Json (7.0.1)
    UnionArgParser (0.6.3)
GITHUB
  remote: forki/FsUnit
    FsUnit.fs (81d27fd09575a32c4ed52eadb2eeac5f365b8348)
  remote: fsharp/FAKE
    src/app/FakeLib/Globbing/Globbing.fs (991bea743c5d5e8eec0defc7338a89281ed3f51a)
  remote: fsprojects/Chessie
    src/Chessie/ErrorHandling.fs (1f23b1caeb1f87e750abc96a25109376771dd090)

GROUP Build
NUGET
  remote: https://nuget.org/api/v2
    FAKE (4.3.1)
    FSharp.Compiler.Service (1.4.0.1)
    FSharp.Formatting (2.10.0)
      FSharp.Compiler.Service (>= 0.0.87)
      FSharpVSPowerTools.Core (1.8.0)
    FSharpVSPowerTools.Core (1.8.0)
      FSharp.Compiler.Service (>= 0.0.87)
    ILRepack (2.0.5)
    Microsoft.Bcl (1.1.10)
      Microsoft.Bcl.Build (>= 1.0.14)
    Microsoft.Bcl.Build (1.0.21)
    Microsoft.Net.Http (2.2.29)
      Microsoft.Bcl (>= 1.1.10)
      Microsoft.Bcl.Build (>= 1.0.14)
    Octokit (0.14.0)
      Microsoft.Net.Http
GITHUB
  remote: fsharp/FAKE
    modules/Octokit/Octokit.fsx (991bea743c5d5e8eec0defc7338a89281ed3f51a)
      Octokit

GROUP Test
NUGET
  remote: https://nuget.org/api/v2
    NUnit (2.6.4)
    NUnit.Runners (2.6.4)

As you can see every group is listed separately and it's possible to let Paket restore only specific groups. If you want to reference dependencies from projects you can do this via the following syntax in the paket.references file.:

1: 
2: 
3: 
4: 
5: 
FSharp.Core

group Test
  NUnit
  NUnit.Runners

Conflict resolution with groups

Paket's group feature allows you to use multiple versions of the same package. Let consider the following paket.dependencies file:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
source https://nuget.org/api/v2

nuget Newtonsoft.Json

group Legacy
    source https://nuget.org/api/v2

    nuget Newtonsoft.Json ~> 6

Every group will be resolved independently to the following paket.lock file:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
NUGET
  remote: https://nuget.org/api/v2
    Newtonsoft.Json (7.0.1)

GROUP Legacy
NUGET
  remote: https://nuget.org/api/v2
    Newtonsoft.Json (6.0.8)

Paket is downloading both version. You will get packages/Newtonsoft.Json with version 7.0.1 and packages/legacy/Newtonsoft.Json with the 6.0.8 bits. In your paket.references file. you can now decide which version you want to use:

1: 
2: 
group Legacy
Newtonsoft.Json // uses 6.0.8
Fork me on GitHub