⬅ Bradenkoh.com

Package Reference Conditional Statement

#Programming

Unlike the old .csproj file, <PackageRefence> nodes will only accept conditional statements that are framework based.

Meaning, only a node like this is acceptable

<ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'net452'" />
</ItemGroup>

You can put the conditional statement in the ItemGroup too

As of 2022-10-07, even the official documentation tells you this.
NuGet PackageReference in project files | Microsoft Learn