Replies: 2 comments
-
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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.Props
file 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