This repository shows an example of controlling NuGet package versions at the repository level, while at the same time ensuring that projects only opt into packages that they want.
Packages are opt'd in as normal via a
<PackageReference> in each project just without a version:
<ItemGroup> <PackageReference Include="Newtonsoft.Json" /> </ItemGroup>
Package versions across the repository (or solution) are then controlled by the
<PackageReference Update=""/> constructs (new for MSBuild 15) inside of Directory.Build.targets:
<ItemGroup> <PackageReference Update="Newtonsoft.Json" Version="10.0.1"/> <PackageReference Update="EntityFramework" Version="6.1.2"/> </ItemGroup>
You can read more information about Directory.Build.props/Directory.Build.targets in Customize your build.