构建项目列表时,将常量字符串附加到TargetName吗?

时间:2018-07-11 13:23:25

标签: msbuild

我有一个.proj文件,其中包含c ++项目文件的列表和几个目标,这些目标使用不同的预处理器宏来构建项目,例如:

<ItemGroup>
  <MyProjectItems Include="$(SourceDir)\Project1\Project1.vcxproj"/>
  <MyProjectItems Include="$(SourceDir)\Project2\Project2.vcxproj"/>
  <MyProjectItems Include="$(SourceDir)\Project3\Project3.vcxproj"/>
  <MyProjectItems Include="$(SourceDir)\Project4\Project4.vcxproj"/>
  <MyProjectItems Include="$(SourceDir)\Project5\Project5.vcxproj"/>
</ItemGroup>

<Target Name="NormalConfiguration">
  <MSBuild Projects="@(MyProjectItems)" 
         Targets="$(BuildTarget)"
         Properties="Configuration=Release;Platform=x86;/>
</Target>


<Target Name="SpecialConfigurationTarget">
  <MSBuild Projects="@(MyProjectItems)" 
         Targets="$(BuildTarget)"
         Properties="Configuration=Release;Platform=x86;SpecialConfiguration=SPECIAL_CONFIGURATION;TargetName=$(ProjectName)_SpecialConfiguration"/>
</Target>

NormalConfiguration目标可以正常工作。运行该目标,并且输出文件夹包含

Project1.exe
Project2.exe
Project3.exe
Project4.exe
Project5.exe

我想做的是在运行SpecialConfigurationTarget时将字符串“ _SpecialConfiguration”附加到可执行文件名称上。因此,在运行SpecialConfigurationTarget之后,输出文件夹将包含

Project1_SpecialConfiguration.exe
Project2_SpecialConfiguration.exe
Project3_SpecialConfiguration.exe
Project4_SpecialConfiguration.exe
Project5_SpecialConfiguration.exe

以上SpecialConfigurationTarget构建了所有MyProjectItems,但使用“ _SpecialConfiguration.exe”作为输出名称。因此,在运行SpecialConfigurationTarget之后,输出文件夹仅包含

 _SpeicalConfiguration.exe

当MSBuild任务正在构建多个项目时,如何获得当前正在构建的项目的名称?

0 个答案:

没有答案