Learn how to use paket
Once you've installed Paket, it's time to learn how to use it!
You can refer to a minimal sample codebase that shows how Paket works in a codebase.
Core concepts
Paket manages your dependencies with three core file types:
paket.dependencies
, where you specify your dependencies and their versions for your entire codebase.paket.references
, a file that specifies a subset of your dependencies for every project in a solution.paket.lock
, a lock file that Paket generates when it runs. When you check it into source control, you get reproducible builds.
You edit the paket.dependencies
and paket.references
files by hand as needed. When you run a paket command, it will generate the paket.lock
file.
All three file types must be committed to source control.
Important paket commands
The most frequently used Paket commands are:
paket install
- Run this after adding or removing packages from thepaket.dependencies
file. It will update any affected parts of the lock file that were affected by the changes in thepaket.dependencies
file, and then refresh all projects in your codebase that specify paket dependencies to import references.paket update
- Run this to update your codebase to the latest versions of all dependent packages. It will update thepaket.lock
file to reference the most recent versions permitted by the restrictions inpaket.dependencies
, then apply these changes to all projects in your codebase.paket restore
- Run this after cloning the repository or switching branches. It will take the currentpaket.lock
file and update all projects in your codebase so that they are referencing the correct versions of NuGet packages. It should be called by your build script in your codebase, so you should not need to run it manually.
Refer to the minimal sample codebase that shows how these commands are used in a codebase.
There is a reference to all paket commands in the table of contents on the right-hand side of this page.
Walkthrough
Create a paket.dependencies
file in your solution's root with the .NET CLI:
1:
|
|
You can also create it by hand.
Make the dependencies file look like this to continue:
1: 2: 3: 4: |
|
Installing dependencies
For every project in your codebase, create a paket.references
file that specifies the dependencies you want to pull in for that project.
In the minimal sample codebase, the library project has Newtonsoft.Json
and the console project has Colorful.Console
.
Once you have a paket.references
file alongside every project in your codebase, install all dependencies with this command:
1:
|
|
Or if you're not using .NET Core,
1:
|
|
The paket install
command will analyze your dependencies and automatically generate the paket.lock
file. It's often quite large!
This file shows all direct and transitive dependencies and pins every dependency to a concrete version. You'll want to commit this file to your version control system (read why).
Updating packages
If you want to check if your dependencies have updates you can run the paket outdated
command:
1:
|
|
Or if you're not using .NET Core:
1:
|
|
If you want to update all packages you can use the paket update
command:
1:
|
|
Or if you're not using .NET Core:
1:
|
|
This command will analyze your paket.dependencies
file and update the paket.lock
file to specify all of the updated dependencies.