Skip to content

Add Required Dependencies to the Main Package for Automatic Inclusion and Central Package Management #330

@Arash-Sabet

Description

@Arash-Sabet

Is your feature request related to a problem? Please describe.
Currently, users of the Xunit.Microsoft.DependencyInjection NuGet package must manually add all required Microsoft.Extensions.* dependencies to their test projects. This manual step is error-prone and leads to confusion or missed dependencies, especially for new users onboarding the package. Additionally, dependency version management across multiple projects in a solution can become inconsistent without central management.

Describe the solution you'd like

  1. Update the main Xunit.Microsoft.DependencyInjection NuGet package to directly reference all required Microsoft.Extensions.* packages via <PackageReference> in its .csproj file. This will allow automatic transitive inclusion of these dependencies when users install the main package, eliminating the need to add each dependency manually.

Required dependencies to add:

  • Microsoft.Extensions.DependencyInjection (Version >= 9.0.9)
  • Microsoft.Extensions.Configuration (Version >= 9.0.9)
  • Microsoft.Extensions.Options (Version >= 9.0.9)
  • Microsoft.Extensions.Configuration.Binder (Version >= 9.0.9)
  • Microsoft.Extensions.Configuration.FileExtensions (Version >= 9.0.9)
  • Microsoft.Extensions.Configuration.Json (Version >= 9.0.9)
  • Microsoft.Extensions.Logging (Version >= 9.0.9)
  • Microsoft.Extensions.Configuration.EnvironmentVariables (Version >= 9.0.9)
  • Microsoft.Extensions.Configuration.UserSecrets (Version >= 9.0.9)

Example addition to the main package .csproj:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Options" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.9" />
  <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.9" />
</ItemGroup>
  1. Implement Directory.Packages.props for Central Package Management
    Add a Directory.Packages.props file at the root of the repository to declare and centrally manage all package versions. This ensures all projects in the solution use consistent package versions, simplifies upgrades, and improves maintainability.

Example Directory.Packages.props file:

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <ItemGroup>
    <PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.9" />
    <PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.9" />
  </ItemGroup>
</Project>

Individual project files should then reference packages without a version:

<PackageReference Include="Microsoft.Extensions.Logging" />
  1. Update the README.md file
    Update the README.md file to reflect the enhancements made in the "section/step 1" above in this issue

Describe alternatives you've considered

  • Creating a meta-package to aggregate all dependencies (not preferred since we control the main package).
  • Providing install scripts or templates (less robust and does not solve the root problem).
  • Relying solely on transitive dependencies (central management is more robust for multi-project solutions).

Additional context
See: Repository README for current manual installation instructions.
See: Central Package Management documentation for details.

These changes will improve the user experience, reduce setup errors, and ensure consistent, maintainable dependency management for all consumers of the package.

Metadata

Metadata

Labels

dependenciesPull requests that update a dependency fileenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions