F# Guide — Paket: Dependency Management for .NET
In this tutorial, you will learn about F# Guide. We cover key concepts, practical examples, and best practices to help you master this topic.
Paket is a dependency manager for .NET projects that complements NuGet with centralized version management, transitive dependency resolution, and support for multiple package sources.
What You'll Learn
- Setting up Paket
- paket.dependencies and paket.lock
- Managing NuGet packages
- Version consolidation
- File references and GitHub dependencies
Why It Matters
Paket gives precise control over dependencies, prevents version conflicts, and supports dependency groups for different environments. Durga Antivirus Pro uses Paket for its .NET components.
Real-World Use
Large .NET projects with complex dependency graphs benefit from Paket's centralized version management and transitive dependency control.
flowchart LR
A["Paket"] --> B["Installation"]
B --> C["paket.dependencies"]
C --> D["Lock File"]
D --> E["Version Mgmt"]
A:::current --> B
style A fill:#2563eb,stroke:#2563eb,color:#fff
style B fill:#dbeafe,stroke:#2563eb,color:#1e40af
style C fill:#dbeafe,stroke:#2563eb,color:#1e40af
style D fill:#dbeafe,stroke:#2563eb,color:#1e40af
style E fill:#f1f5f9,stroke:#94a3b8,color:#64748b
Installation
# Install Paket globally
dotnet tool install Paket --global
# Initialize in project
paket init
# Add NuGet source
paket add nuget FSharp.Data --project MyProject.fsproj
# Install dependencies
paket install
paket.dependencies
// paket.dependencies
source https://api.nuget.org/v3/index.json
nuget FSharp.Core >= 6.0
nuget FSharp.Data >= 5.0
nuget Newtonsoft.Json >= 13.0
// Group for test dependencies
group Test
source https://api.nuget.org/v3/index.json
nuget xunit >= 2.4
nuget FsCheck >= 2.14
paket.references
// MyProject/paket.references
FSharp.Core
FSharp.Data
Newtonsoft.Json
// MyProject.Tests/paket.rereferences
group Test
xunit
FsCheck
Adding Packages
# Add single package
paket add nuget Serilog --project MyApp.fsproj
# Add to specific group
paket add nuget xunit --group Test --project MyApp.Tests.fsproj
# Convert from packages.config
paket convert-from-nuget
Version Constraints
// paket.dependencies version syntax
nuget FSharp.Core >= 6.0 // Minimum version
nuget FSharp.Data ~> 5.0 // Compatible version (5.x)
nuget Newtonsoft.Json >= 13.0 < 14.0 // Range
nuget MyLib prerelease // Include prerelease
Updating Dependencies
# Update all packages
paket update
# Update specific package
paket update nuget FSharp.Data
# Show outdated packages
paket outdated
# Why a package is included
paket why FSharp.Data
Common Mistakes
1. Mixing Paket and NuGet
Don't use both Paket and packages.config. Choose one approach.
2. Forgetting paket install
Always run paket install after modifying paket.dependencies.
3. Committing paket.lock
Always commit paket.lock for reproducible builds.
4. Incorrect version constraints
Overly restrictive versions cause conflicts. Use compatible version ranges.
5. Ignoring transitive dependencies
Paket resolves transitive deps. Run paket show-installed to see the full graph.
Practice Questions
1. What is Paket? An alternative .NET dependency manager that provides centralized version control and transitive dependency resolution.
2. How is Paket different from NuGet? Paket uses a single paket.dependencies file for all projects, separate paket.references per project, and a lock file for reproducibility.
3. What is the paket.lock file used for? It records the exact versions and dependency graph, ensuring reproducible builds across environments.
Challenge: Set up Paket for a multi-project solution with shared and test-specific dependencies.
FAQ
{{< faq question="Should I use Paket or NuGet?" >} For simple projects, NuGet is fine. For multi-project solutions with complex dependencies, Paket's centralized control and lock file are beneficial. {{< /faq >}}
{{< faq question="Can I use both Paket and NuGet?" >} Not recommended. Choose one approach. Paket can replace NuGet entirely for dependency management. {{< /faq >}}
{{< faq question="Is Paket still maintained?" >} Yes. Paket is actively maintained by the F# community and the .NET Foundation. {{< /faq >}}
{{< faq question="How does Paket handle transitive dependencies?" >} Paket resolves the dependency graph and consolidates versions. The lock file records exact transitive versions. {{< /faq >}}
{{< faq question="Can Paket download dependencies from GitHub?" >} Yes. Paket supports file references from GitHub repos and HTTP sources, not just NuGet. {{< /faq >}}
Mini Project
Set up Paket for a solution with shared and test dependencies:
// paket.dependencies
source https://api.nuget.org/v3/index.json
nuget FSharp.Core ~> 7.0
nuget FSharp.Data
group Test
source https://api.nuget.org/v3/index.json
nuget xunit ~> 2.4
nuget FsCheck
nuget FsUnit
// src/MyApp/paket.references
FSharp.Core
FSharp.Data
// tests/MyApp.Tests/paket.references
group Test
xunit
FsCheck
FsUnit
What's Next
Now that you understand Paket, explore common F# libraries and the ecosystem.
| Topic | Description | Link |
|---|---|---|
| F# Common Libraries | F# ecosystem | {{< ref "30-common-libraries" >}} |
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro