以下内容来自常规的VS2010 C++项目。
如果我编辑
然而,如果我使用以下内容:
我可以通过消息看到
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
如果我编辑
PreprocessorDefinitions
,我可以设置一个被预处理器使用的定义。我可以通过#ifdef
等在我的代码中看到这一点。然而,如果我使用以下内容:
<Target Name="NormalBuild" Condition=" '$(_InvalidConfigurationWarning)' != 'true' " DependsOnTargets="_DetermineManagedStateFromCL;CustomBeforeBuild;$(BuildDependsOn)" Returns="@(ManagedTargetPath)">
<ItemGroup>
<ManagedTargetPath Include="$(TargetPath)" Condition="'$(ManagedAssembly)' == 'true'" />
</ItemGroup>
<Message Text="PreprocessorDefinitions: $(PreprocessorDefinitions)" Importance="High" />
</Target>
<Target Name="TestBuild" Returns="@(ManagedTargetPath)">
<MSBuild Projects="demo.vcxproj" Targets="NormalBuild" Properties="PreprocessorDefinitions=THISGETSSETBUTDOESNOTHING"/>
</Target>
我可以通过消息看到
PreprocessorDefinitions
包含我通过Properties="PreprocessorDefinitions=THISGETSSETBUTDOESNOTHING"
设置的值,但是我无法使用#ifdef
等来控制我的构建。
如果我使用常规设置并尝试使用<Message Text="PreprocessorDefinitions: $(PreprocessorDefinitions)"
输出PreprocessorDefinitions
,则该字段实际上为空,并且不包含预期的<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
,尽管我可以使用其中任何一个键来使用#ifdef
等来控制我的构建。
- 为什么会这样?
- 我应该如何通过任务的
Properties
元素传递PreprocessorDefinitions给VS2010 C++项目?