NuGet dependencies
Paket allows to reference NuGet packages in your application.
Sources
Sources are defined by the source <address>
statement.
Paket supports multiple sources in one
paket.dependencies
. It's recommended to put all
source
statements at the top of
paket.dependencies
.
The paket.lock
file will reflect the sources selected by
dependency resolution.
NuGet feeds
Paket supports NuGet feeds like those provided by nuget.org, MyGet or TeamCity.
Please note that you need to specify all NuGet sources, including the default feed from nuget.org. Paket does not take the current machine's NuGet Package Sources configuration (that you set up e.g. using Visual Studio) into account.
1: 2: |
|
It's also possible to provide login information for private NuGet feeds:
1:
|
|
If you don't want to check your username and password into source control, you can use environment variables instead:
1:
|
|
%PRIVATE_FEED_USER%
and %PRIVATE_FEED_PASS%
will be expanded with the
contents of your PRIVATE_FEED_USER
and PRIVATE_FEED_PASS
environment
variables.
The paket.lock
file will also reflect these settings.
authtype
is an optional parameter to specify the authentication scheme. Allowed
values are basic
and ntlm
. If no authentication type is specified, basic
authentication will be used.
Note: If paket.dependencies
file exists while
running the convert-from-nuget
command, the
PRIVATE_FEED_USER
and PRIVATE_FEED_PASS
will not be expanded. Please see
this document for instructions on
migrating credentials.
Path sources
Paket also supports file paths such as local directories or references to UNC shares:
1: 2: 3: |
|
Paket supports the source directory to be specified relative to the
paket.dependencies
file as well:
1: 2: |
|
Dependencies
The dependencies of your project are defined by the nuget <package ID> <version
constraint>
statement.
Paket also supports file dependencies, such as referencing files directly from GitHub repositories.
Package ID
The package ID
parameter is the same as you find in NuGet's packages.config
or on nuget.org.
Version constraints
One key feature of Paket is that it separates the definition of dependencies
from the actual resolution. NuGet stores resolution information in
packages.config
, where both package IDs and their respective pinned version
are combined.
With Paket you do not need to pin specific versions (although you can). Paket allows you to leverage semantic versioning and define version constraints in a very flexible manner.
You can also influence the resolution of transitive dependencies.
Pinned version constraint
1: 2: 3: 4: |
|
This is the strictest version constraint. Use the =
operator to specify an
exact version match; the =
is optional.
Omitting the version constraint
If you omit the version constraint then Paket will assume >= 0
:
1:
|
|
"Use exactly this version" constraint
We consider a situation with 3 packages
A
,B
andC
.
A
andB
are direct (or root-level) dependencies, but both have a dependency onC
.A
needs exactlyC 1.0
andB
wants versionC 1.1
. This is a version conflict and Paket will complain during resolution phase.If we specify
C = 1.1
in thepaket.dependencies
file then Paket still considers this as a version conflict with the version requirement inA
. By specifyingC == 1.1
we overwrite all other requirements and Paket will not complain about the conflict anymore.
If your transitive dependencies result in a version
conflict you might want to instruct Paket to use a specific version. The ==
operator allows you to manually resolve the conflict:
1:
|
|
Note: If you want to restrict the version to a specific version then
use the = operator
. The
==
operator should only be used if you need to overwrite a dependency
resolution due to a conflict.
Further version constraints
1: 2: 3: 4: 5: |
|
Pessimistic version constraint
1:
|
|
The ~>
"twiddle-wakka" operator is borrowed from
bundler. It is used to specify a version range.
It translates to:
Use the minimum version specified, but allow upgrades up to, but not including,
<version specified>
, last part chopped off, last number incremented by 1.
In other words, allow the last part stated explicitly to increase, but pin any of the elements before that.
Let us illustrate:
Constraint |
Version range |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Pessimistic version constraint with compound
If want to allow newer backward-compatible versions but also need a specific fix version within the allowed range, use a compound constraint.
1:
|
|
The example above translates to 1.2.3 <= x < 2.0
.
Prereleases
If you want to depend on prereleases then Paket can assist you. In contrast to NuGet, Paket allows you to depend on different prerelease channels:
1: 2: 3: 4: |
|
Framework restrictions
Sometimes you do not want to generate dependencies for other .NET Framework
versions than the ones your projects use. You can control this in the
paket.dependencies
file.
The framework
modifier tells Paket to only consider the specified frameworks
for a package:
1:
|
|
It translates to:
I use
Example
only to compile againstnet35
andnet40
. I never compile projects against another framework likenet45
.
Another example restricts to frameworks greater or equal than:
1:
|
|
Note: This feature is deprecated and can be seen as an expert feature. Using framework restrictions on a single package might make you projects uncompilable. It is recommended to specify the frameworks you want to compile for globally or for a group).
Putting the version number in the path
If you need to be NuGet-compatible and want to have the package version number
in the package path below packages
you can do the following:
1: 2: 3: |
|
You need this if you are using custom test runners in Visual Studio,
like xunit.runners.visualstudio
or MSTest.TestAdapter
.
The Visual Studio Test Runner caches the
packages
in %TEMP%\VisualStudioTestExplorerExtensions
,
and depends on the directory names being unique per version, and the presence of a packages.config in the test project.
Adding the version_in_path
flag makes your unit tests appear in the Visual Studio Test Explorer again.
Controlling whether content files should be copied to the project
The content
modifier controls the installation of any content files:
1: 2: 3: 4: 5: |
|
The default is content: true
. content: false
is equivalent to setting ExcludeAssets=contentFiles
for a PackageReference
in NuGet.
Controlling whether content files should be copied to the output directory during build
It's possible to influence the
CopyToOutputDirectory
property
for content references via the copy_content_to_output_dir
modifier:
1: 2: 3: 4: 5: |
|
Controlling whether assemblies should be copied to the output directory during build
It's possible to influence the
Private
property
for references via the copy_local
modifier:
1: 2: 3: |
|
The default is copy_local: true
. copy_local: false
is equivalent to setting ExcludeAssets=runtime
for a PackageReference
in NuGet.
Importing *.targets
and *.props
files
If you don't want to import *.targets
and *.props
files from packages, you
can disable it via the import_targets
modifier:
1: 2: 3: |
|
import_targets: false
is equivalent to setting ExcludeAssets=build;buildMultitargeting;buildTransitive
for a PackageReference
in NuGet.
License download
If you want paket to download licenses automatically you can use the license_download
modifier. It is disabled by default.
1: 2: 3: |
|
Controlling assembly binding redirects
You can instruct Paket to create Assembly Binding Redirects for NuGet packages:
1: 2: 3: |
|
Redirects are created only if they are required. However, you can instruct Paket to create them regardless:
1: 2: 3: |
|
In contrast, you may force Paket to not create a redirect:
1: 2: 3: |
|
You can also override the redirects settings per project, from its
paket.references
file.
Referencing specific versions in projects
It's possible to influence the
SpecificVersion
property
for references via the specific_version
modifier:
1: 2: 3: |
|
Strategy modifiers
To override the
strategy
option
you can use one of the strategy
modifiers below.
Note, however, that all direct dependencies will still get their latest
matching versions, no matter the value of the strategy
option. If you want to
influence the resolution of direct dependencies then read about the
lowest_matching
option.
The max
modifier
To override the resolver strategy for the
transitive dependencies of a package, use the
strategy: max
setting:
1: 2: 3: 4: |
|
This effectively will get you the latest matching versions of Example
's
dependencies.
The following code is doing the same by using the @
operator in
your version constraint:
1: 2: 3: 4: |
|
The min
modifier
To override the resolver strategy for the
transitive dependencies of a package, use the
strategy: min
modifier:
1: 2: 3: |
|
This effectively will get you the lowest matching versions of Example
's
dependencies. Still, you will get the latest matching version of Example
itself according to its
version constraint of 1.2 <= x <2
.
The following code is doing the same by using the !
modifier in your version
constraint:
1: 2: 3: |
|
The strategy modifier and the corresponding !
and @
modifiers are applicable
to all version constraints:
1: 2: 3: 4: 5: 6: |
|
Resolver strategy for direct dependencies
To override the
lowest_matching
option
you can use the following modifier.
Note, however, that all transitive dependencies will
still get their latest matching versions, no matter the value of the
lowest_matching
modifier. If you want to influence the resolution of transitive
dependencies then read about the strategy
option.
To request Paket to override the resolver strategy for a package, use the
lowest_matching: true
modifier:
1: 2: 3: |
|
Combine multiple modifiers
It is possible to apply more than one of the modifiers above to a particular package. To do so, simply separate them by commas:
1: 2: 3: 4: |
|
Special case: dotnet
CLI tools
1: 2: |
|
Command line (CLI) tools that hook into the dotnet
CLI are special NuGet
packages. These packages are added with the keyword clitool
instead of
nuget
. This will exclude the tool and all its dependencies from getting
referenced as a dependency for any project.