【发布时间】:2012-03-07 12:37:38
【问题描述】:
我有一个 WPF 解决方案,其中包含一个带有 WPF 和 Silverlight 代码的子项目组件。如果定义了“WPF”条件编译符号,则构建 WPF 代码,如果未定义,则构建 Silverlight 代码。这适用于我的调试版本就好了。但是,当我尝试进行 Release 构建时,该构建没有检测到“WPF”符号,并且因为它错误地编译了 silverlight 代码,所以我得到了一个不起作用的构建。任何想法为什么构建没有检测到 WPF 符号?
这是 .csproj 的相关部分。请注意,在 DefineConstants 中为 Debug 和 Release 定义了“WPF”符号,但在发布版本中未检测到它。有人可以帮忙吗?
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;WPF</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1607</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;WPF</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
【问题讨论】:
-
定义“未检测到” - 您应用了哪些预处理器指令?
-
@KMoraz 预处理器指令(符号)通过项目属性 > 构建选项卡 > 条件编译符号字段应用;如上所示,它存储在 DefineConstants 标记中的 .csproj 文件中。据我了解,这与#define TRACE #define WPF 等相同
-
@KMoraz 通过“未检测到”我的意思是我的代码中有“#if WPF”语句,但是虽然这对于 Debug 构建按预期工作,但 Release 版本构建就像 WPF 预处理器指令一样不存在因此将错误的代码编译到构建中
标签: visual-studio-2010 msbuild