Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional package reference in UWP project

I would like to use one NuGet package just for Debug configuration. I found possibility to do it in Visual Studio 2017 if I have a UWP project targeting Creators Update (15063).

<PackageReference Include="Newtonsoft.json" Version="9.0.1" Condition="'$(Configuration)' == 'Debug'" />

But the package is still there also for Release configuration.

like image 757
Jakub Krampl Avatar asked Apr 30 '26 11:04

Jakub Krampl


2 Answers

<Choose>  
    <When Condition=" '$(Configuration)'=='Debug' ">  
        <ItemGroup>
            <PackageReference Include="Newtonsoft.json" Version="9.0.1" />
        </ItemGroup>
    </When>
</Choose>

The PackageReference has to be in an ItemGroup than it works.

like image 126
user2007755 Avatar answered May 03 '26 02:05

user2007755


Currently, you cannot condition on Configuration. Please file a feature ask on NuGet GitHub repo.

The only supported condition is TargetFramework

like image 25
karann - MSFT Avatar answered May 03 '26 01:05

karann - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!