Skip to content

Pinning a Nuget Package Version

It is possible to pin the version of a NuGet package (i.e. prevent it updating to a newer version) by surrounding the version number in square braces in the project file, for example to fix the version of the System.ComponentModel.Annotations model to 5.0.0, update the reference in the project file as below:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
      <PackageReference Include="System.ComponentModel.Annotations" Version="[5.0.0]" />
  </ItemGroup>
</Project>

This is useful for situations such as where Fluent Assertions changed it's licence between version 7.x and 8.0, or just where other breaking changes are introduced in later library versions.