创建UWP项目时MSBuild条件被忽略的技术问询
MSBuild解析UWP项目时忽略条件判断的异常问题
MSBuild在处理空白UWP项目时存在异常行为:会忽略项目文件中的条件判断逻辑,导致明明不满足条件的代码被执行,进而引发错误。
复现步骤
- 打开Visual Studio 2022
- 创建「空白应用(通用Windows)」项目
- 用文本编辑器打开项目的
.csproj文件 - 在最后一个
<Import>语句前插入以下代码:
<ItemGroup Condition="''=='Do never include this here'"> <PackageReference Include="I am included, hahaha. I ignore your condition" Version="16.7" /> </ItemGroup>
- 生成解决方案
错误输出
NU1101: Unable to find package I am included, hahaha. I ignore your condition. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org
对比测试情况
- 在C#控制台应用中执行相同步骤,条件判断可正常生效,不符合条件的
PackageReference不会被处理 - 即使将条件直接写在
PackageReference节点上(如<PackageReference ... Condition="''=='Do never include this here'" />),UWP项目中仍会被忽略
希望了解该问题的原因,或确认这是否为已知Bug。
内容的提问来源于stack exchange,提问作者Samuel
相关产品推荐
相关产品推荐

