⬅ Bradenkoh.com

Package Reference Conditional Statement


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

Meaning, only a node like this is acceptable

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

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