You could use nuget's new "Central Package Management" feature.
Example problem:
Suppose you have monorepo (i.e. VS "solution" or VSCode "workspace") with multiple projects.
ProjectA.csproj
:
<ItemGroup>
<PackageReference Include="Foo.Bar.Baz" Version="1.0.0" />
<PackageReference Include="Spam.Ham.Eggs" Version="4.0.0" />
</ItemGroup>
ProjectB.csproj
:
<ItemGroup>
<PackageReference Include="Foo.Bar.Qux" Version="1.2.3" />
<PackageReference Include="Spam.Ham.Eggs" Version="4.5.6" />
</ItemGroup>
Some items are the same whereas others differ. And you need to remember to keep the versions in sync - the example shows that you forgot to do that!
Step 1: remove the versions
ProjectA.csproj
:
<ItemGroup>
<PackageReference Include="Foo.Bar.Baz" />
<PackageReference Include="Spam.Ham.Eggs" />
</ItemGroup>
ProjectB.csproj
:
<ItemGroup>
<PackageReference Include="Foo.Bar.Qux" />
<PackageReference Include="Spam.Ham.Eggs" Version="4.0.0" /> <!-- note version override for this project -->
</ItemGroup>
Step 2: add file named Directory.Packages.props
to your repo's root
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<!-- use 'PackageVersion' rather than 'PackageReference' -->
<PackageVersion Include="Foo.Bar.Baz" Version="1.2.3" />
<PackageVersion Include="Foo.Bar.Qux" Version="1.2.3" />
<PackageVersion Include="Spam.Ham.Eggs" Version="4.5.6" />
</ItemGroup>
</Project>
Step 3: restore
For each project:
- clear build output:
dotnet clean
- restore packages:
dotnet restore
All your projects will now use the versions you've specified in the config file.
There are more options, like version overrides, and transitive dependency pinining - read the docs for more.