Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

Overview

This PR addresses issue #[issue_number] by implementing automatic dependency inclusion and central package management for the Xunit.Microsoft.DependencyInjection library. Users no longer need to manually install Microsoft.Extensions.* dependencies - they're now automatically included when installing the main package.

Changes Made

1. Central Package Management

  • Added Directory.Packages.props at the repository root to centrally manage all package versions
  • Ensures consistent dependency versions across all projects in the solution
  • Follows Microsoft's recommended approach for multi-project solutions

2. Automatic Dependency Inclusion

Updated the main package to include all required Microsoft.Extensions dependencies as direct references:

<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />

These dependencies are now transitively included when users install the main package, eliminating manual setup steps.

3. Simplified Installation Documentation

Updated the README.md to reflect the streamlined installation process:

Before:

<!-- Users had to manually add all these -->
<PackageReference Include="Xunit.Microsoft.DependencyInjection" Version="9.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.9" />
<!-- ... 7 more manual dependencies -->

After:

<!-- Single package installation -->
<PackageReference Include="Xunit.Microsoft.DependencyInjection" Version="9.2.0" />

4. Example Project Updates

  • Removed explicit Microsoft.Extensions package references from the example project
  • Added comments showing which dependencies are now automatically included
  • Demonstrates the simplified workflow for future users

Benefits

  • Reduced Setup Friction: New users can get started with a single package installation
  • Eliminates Version Conflicts: Central management prevents dependency version mismatches
  • Better Maintainability: Single source of truth for all package versions
  • Improved User Experience: No more "missing dependency" errors during setup

Verification

All existing functionality remains unchanged:

  • ✅ 43 tests continue to pass
  • ✅ All dependency injection patterns work correctly
  • ✅ Configuration, logging, and keyed services function as expected
  • ✅ NuGet package builds successfully with all dependencies included

Breaking Changes

None. This is a purely additive change that maintains full backward compatibility. Existing projects will continue to work without any modifications.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Required Dependencies to the Main Package for Automatic Inclusion and Central Package Management</issue_title>
<issue_description>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.</issue_description>

#...

Fixes #330


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

- Created Directory.Packages.props for central package management
- Updated main package to include all required Microsoft.Extensions dependencies
- Updated example tests to use central package management
- Updated README to reflect automatic dependency inclusion
- All 43 tests still passing

Co-authored-by: Arash-Sabet <26050123+Arash-Sabet@users.noreply.github.com>
Copilot AI changed the title [WIP] Add required dependencies to main package for automatic inclusion Add automatic dependency inclusion and central package management Oct 16, 2025
Copilot AI requested a review from Arash-Sabet October 16, 2025 16:25
Copilot finished work on behalf of Arash-Sabet October 16, 2025 16:25
Bump Microsoft.Extensions.* packages to 9.0.10 and Microsoft.NET.Test.Sdk to 18.0.0. Update .NET SDK version in pipelines to 9.0.306 and increment project/package version to 9.2.2.
@Arash-Sabet Arash-Sabet marked this pull request as ready for review October 17, 2025 02:12
Deleted commented-out PackageReference entries for Microsoft.Extensions.* packages that are now included automatically via the main package. This cleans up the project file and reduces confusion.
@Arash-Sabet Arash-Sabet merged commit 85aa8a1 into main Oct 17, 2025
1 check passed
@Arash-Sabet Arash-Sabet deleted the copilot/add-required-dependencies-package branch October 17, 2025 02:16
@Arash-Sabet Arash-Sabet linked an issue Oct 17, 2025 that may be closed by this pull request
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade the NuGet packages of .NET 9.0 Add Required Dependencies to the Main Package for Automatic Inclusion and Central Package Management

2 participants