以下内容来自常规的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>
Run Code Online (Sandbox Code Playgroud)
如果我编辑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>
Run Code Online (Sandbox Code Playgroud)
我也可以通过消息看到PreprocessorDefinitions包含我设置的值,Properties="PreprocessorDefinitions=THISGETSSETBUTDOESNOTHING"但我无法控制我的构建使用#ifdef等.如果我使用常规设置并尝试输出PreprocessorDefinitions使用<Message Text="PreprocessorDefinitions: $(PreprocessorDefinitions)"该字段实际上是空白,并不包含预期,<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>虽然我可以使用用于控制构建的任何一个键使用#ifdef等.
Properties元素传递VS2010 C++项目的PreprocessorDefinitions ?msbuild ×1