Skip to content

[Build] Centrally manage NuGet package versions #4180

Closed
CommunityToolkit/dotnet
#96
@Nirmal4G

Description

@Nirmal4G

Describe the problem this feature would solve

NuGet package references are spread across project files. It is difficult to track versions and upgrade them properly. It would be simple and easier to manage the versions and the packages centrally, if there were a way to store versions, separately in a central location, away from the project files. In the future, you could also separate testing versions from shipping versions and use them in CI build intelligently. But this would require re-organizing the project's folder structure. If this works, I'll open a proposal to re-organize the projects to effectively use modern build features that are at our disposal.

Describe the solution

Use NuGet's upcoming feature to manage package versions centrally using Directory.Packages.props with the following item spec to store a package version.

  <ItemGroup>
    <PackageVersion Include="Vendor.Awesome.Package" Version="11.0.0" />
  </ItemGroup>

Then, all you need to remove the version tag/attribute from all the project files, like so...

  <ItemGroup>
-    <PackageReference Include="Vendor.Awesome.Package" Version="11.0.0" />
+    <PackageReference Include="Vendor.Awesome.Package" />
  </ItemGroup>

  <ItemGroup>
-    <PackageReference Include="Vendor.Awesome.Package">
-      <Version>11.0.0</Version>
-    </PackageReference>
+    <PackageReference Include="Vendor.Awesome.Package" />
  </ItemGroup>

Describe alternatives you've considered

There is a Microsoft.Build.CentralPackageVersions, an MSBuild SDK which is a part of MSBuild SDKs maintained by @jeffkl. But for simple scenarios like ours, I've decided to go with the built-in support from NuGet's feature. It enables us to dogfood the feature and give feedback to the NuGet team.

Additional context & Screenshots

Know more about NuGet's Central Package Version Management (CPVM) feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions