Skip to content

Centralize package metadata and dependency versions with Directory.Build.props and Directory.Packages.props #8

Closed

Description

@rd-rtca

Problem

Shared configuration is copy-pasted across the solution.

Package metadata is duplicated in all 10 packable projects. Each one repeats an identical block:

<Version>2.1.0</Version>
<Authors>Romain-OD</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Romain-OD/MessageValidation</PackageProjectUrl>
<RepositoryUrl>https://github.com/Romain-OD/MessageValidation</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>MessageValidation-logo.png</PackageIcon>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>14.0</LangVersion>

Cutting a release therefore means editing <Version> in 10 separate files and getting all 10 right. One missed file ships a package at the wrong version, and the mistake is invisible until it is on NuGet.org and immutable.

Dependency versions are duplicated across all 22 projects. Microsoft.Extensions.* at 10.0.5 appears in roughly 14 files; xunit 2.9.3, Microsoft.NET.Test.Sdk 18.3.0, xunit.runner.visualstudio 3.1.5, and NSubstitute 5.3.0 each appear in about 10. Nothing prevents two projects from silently drifting to different versions of the same package.

This is maintainer friction rather than a consumer-facing defect, but it directly raises the cost and risk of every release — which is exactly what makes releases infrequent.

Proposed change

1. Directory.Build.props at the repository root — shared metadata and compiler settings in one place, with a single <Version>:

<Project>
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <LangVersion>14.0</LangVersion>
  </PropertyGroup>

  <PropertyGroup Condition="'$(IsPackable)' != 'false'">
    <Version>2.1.0</Version>
    <Authors>Romain-OD</Authors>
    <PackageLicenseExpression>MIT</PackageLicenseExpression>
    <PackageProjectUrl>https://github.com/Romain-OD/MessageValidation</PackageProjectUrl>
    <RepositoryUrl>https://github.com/Romain-OD/MessageValidation</RepositoryUrl>
    <RepositoryType>git</RepositoryType>
    <PackageReadmeFile>README.md</PackageReadmeFile>
    <PackageIcon>MessageValidation-logo.png</PackageIcon>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>
</Project>

Each .csproj then keeps only what is genuinely its own: PackageId, Description, PackageTags, and its PackageReference / ProjectReference items.

2. Directory.Packages.props — central package management:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.5" />
    <PackageVersion Include="xunit" Version="2.9.3" />
    <!-- ... -->
  </ItemGroup>
</Project>

Individual projects drop the Version attribute: <PackageReference Include="xunit" />.

Follow-on, not part of this issue

Once metadata is centralized, <EnablePackageValidation>true</EnablePackageValidation> with PackageValidationBaselineVersion becomes a one-line addition and would catch accidental breaking API changes against the previously shipped version.

Acceptance criteria

  • Directory.Build.props holds the shared metadata; a release requires changing <Version> in exactly one file
  • Directory.Packages.props exists with ManagePackageVersionsCentrally, and no .csproj carries an inline Version attribute
  • Each .csproj retains its own PackageId, Description, and PackageTags
  • dotnet build MessageValidation.slnx -c Release succeeds with no new warnings
  • dotnet pack output is byte-equivalent in metadata to the current 2.1.0 packages (same version, license, icon, readme, docs XML)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions