Does anyone have any experience of conditionally including a NuGet package in a build? Ideally it would be good if this could be done based on build configuration so for example package A gets included in a Debug build but package B is used instead in a Release build.
Is this possible?
You can edit your .csproj file and include below ItemGroup sections to include any packages conditionally.
<ItemGroup Condition="'$(Configuration)'=='Debug'">
//Move any package reference here that will only be available in debug mode
<PackageReference Include="PackageA" Version="1.0.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Release'">
//Move any package reference here that will only be available in release mode
<PackageReference Include="PackageB" Version="1.0.0.0" />
</ItemGroup>
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With