以下内容来自常规的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 ?我目前正在尝试使用#ifdef标签在Visual C++ .rc文件中切换几个不同的默认图标.
切换#define值的构建是使用MSBuild通过命令行创建的.
我遇到的困难是使用Visual Studio 2010,为了将预处理器定义传递给资源编译器,您必须在项目设置中定义它(Config Properties - > Resources - > General).
这使得使用#ifdef标记变得困难,因为使用此方法始终会在资源编译器中定义它.
我希望将它定义为一个值,以便我可能使用预处理器#if SOMEVALUE == 4可能会工作,但似乎无法找到通过命令行将预处理器定义+值传递给MSBuild的方法.
有没有人知道将预处理器定义直接传递给资源编译器的方法,或者通过命令行为msbuild定义预处理器定义的值的方法?