-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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.
- 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>
- .csproj
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net9.0</TargetFrameworks>
</PropertyGroup>
<PackageReference Include="System.Text.Json" />
- Build the project for net9.0 or netStandard target framework.
Expected Behavior
- CPM should apply the version
9.0.6
fornet9.0
from central config. - CPM should honor the version
6.0.3
fornetstandard2.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