You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 15:35:20