Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally Including a NuGet Package

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?

like image 853
user3617723 Avatar asked May 10 '16 07:05

user3617723


1 Answers

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.

like image 142
Arkadas Kilic Avatar answered Oct 23 '22 01:10

Arkadas Kilic