Skip to content

Central package management is not working for multi-targeted projects #49614

@jatinrdave

Description

@jatinrdave

Describe the bug

Central Package Management (CPM) is not resolving package versions correctly in multi-targeted projects. When a project targets multiple frameworks (e.g., netstandard2.0 and net9.0), the condition-based PackageReference entries doesn't require to add version in library in individual projects. It should use central versions from directory.build.props for given target project.

To Reproduce

It should resolve project targets multiple frameworks (e.g., netstandard2.0 and net9.0) for given library when project builds.

  1. directory.build.props
<Project>
<ItemGroup>
  <PackageVersion Include="System.Text.Json" Version="9.0.6" Condition="'$(TargetFramework)' == 'net9.0'" />
  <PackageVersion Include="System.Text.Json" Version="6.0.3" Condition="'$(TargetFramework)' == 'netstandard2.0'"/>
</ItemGroup>
</Project>
  1. .csproj
<PropertyGroup>
       <TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
</PropertyGroup>

<PackageReference Include="System.Text.Json" />
  1. Build the project for net9.0 or netStandard target framework.

Expected Behavior

  • CPM should apply the version 9.0.6 for net9.0 from central config.
  • CPM should honor the version 6.0.3 for netstandard2.0.

Actual Behavior

  • CPM doesn't applies the central version to target framework or fails to resolve the correct version per target.
  • This leads to build-time confusion or runtime issues due to API version mismatches.

Exceptions (if any)

Compile-time exceptions occur when a target framework uses an incompatible version of the package (e.g., missing APIs in System.Text.Json for netstandard2.0).

The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) The type or namespace name 'Serialization' does not exist in the namespace 'System.Text.Json' (are you missing an assembly reference?)

Further technical details

  • .NET SDK:

    .NET SDK (reflecting any global.json):
     Version: 9.0.100-preview.6.24327.3
     Commit:  bbc4b10d04
  • IDE:

    • Visual Studio 2022 v17.10.2

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