In one of our applications we encountered an issue due to incompatible package versions. Therefore it was important that we still could update to newer minor versions but don't accidently update to a next major version.
The trick to get this done is through version ranges.
By default a āminimum versionā is used when adding a NuGet dependency:
<Project Sdk="Microsoft.NET.Sdk"> | |
<!-- rest of project file contents omitted --> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" /> | |
</ItemGroup> | |
</Project> |
But this is not the only option. Here is the list of possible notations:
Notation | Applied rule | Description |
1.0 | x ā„ 1.0 | Minimum version, inclusive |
(1.0,) | x > 1.0 | Minimum version, exclusive |
[1.0] | x == 1.0 | Exact version match |
(,1.0] | x ā¤ 1.0 | Maximum version, inclusive |
(,1.0) | x < 1.0 | Maximum version, exclusive |
[1.0,2.0] | 1.0 ā¤ x ā¤ 2.0 | Exact range, inclusive |
(1.0,2.0) | 1.0 < x < 2.0 | Exact range, exclusive |
[1.0,2.0) | 1.0 ā¤ x < 2.0 | Mixed inclusive minimum and exclusive maximum version |
Next to the above notations, you can also use floating versions:
Version | Versions present on server | Resolution | Reason |
* | .1.0 1.1.1 1.2.0 1.3.0-alpha 1.2.0 | 1.2.0 | The highest stable version. |
1.1.* | 1.1.0 1.1.1 1.1.2-alpha 1.2.0-alpha | 1.1.1 | The highest stable version that respects the specified pattern. |
*-* | 1.1.0 | 1.3.0-beta | The highest version including the not stable versions. |
1.1.*-* | 1.1.0 | 1.1.2-beta | The highest version respecting the pattern and including the not stable versions. |
In our case we wanted to be sure that the Nuget package was not updated to a next major version. To achieve this, we used the following notation:
<Project Sdk="Microsoft.NET.Sdk"> | |
<!-- rest of project file contents omitted --> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.*" /> | |
</ItemGroup> | |
</Project> |