Conditional package reference in UWP project

≯℡__Kan透↙ 提交于 2019-12-11 02:29:46

问题


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.


回答1:


<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.




回答2:


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

The only supported condition is TargetFramework




回答3:


You can use Choose/When as a workaround:

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


来源:https://stackoverflow.com/questions/44803176/conditional-package-reference-in-uwp-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!