Replies: 2 comments 1 reply
-
|
Fyi @jeffkl |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
In MSBuild, all properties and imports are evaluated first. Items are then evaluated second. Since ClassLibrary1.csproj<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
</Project>Directory.Packages.props<Project>
<PropertyGroup>
<!-- Enable central package management -->
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="12.0.1" Condition="'$(TargetFramework)' == 'net472'" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" Condition="'$(TargetFramework)' != 'net472'" />
</ItemGroup>
</Project>If its not working as expected, please do a command-line based restore and attach |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
How would one use conditions on the TargetFramework with CentralPackageVersionManagement (using Directory.Packages.props).
In case you have projects with different TargetFramework and needing to use a different version based on the TargetFramework.
Example Directory.Packages.Props
As far as I can tell the
Directory.Packages.Propsfile is imported before the TargetFramework Property is set in a normal csproj file causing the conditions to evaluate to empty and thus not working.Beta Was this translation helpful? Give feedback.
All reactions