2016-11-20 3 views
0

J'essaie d'appeler la tâche msbuild pour tous les fichiers de projet avec des propriétés. J'appelle la tâche msbuild quatre fois avec des configurations codées en dur et une combinaison de plates-formes. Quelque chose commePasser des propriétés à MSBUILD Tâche

<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="Configuration=Debug;Platform=Win32" BuildInParallel="true"/> 
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="Configuration=Debug;Platform=x64" BuildInParallel="true"/> 
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="Configuration=Release;Platform=Win32" BuildInParallel="true"/> 
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Build" Properties="Configuration=Release;Platform=x64" BuildInParallel="true"/> 

Mais je veux offrir cette propriété comme ItemGroup quelque chose comme ça

Configuration=%(BUILD_CONFIG.Identity);Platform=%(BUILD_PLATFORM.Identity) 

code échantillon MyProject.vcxproj

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="BuildAll" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<Import Project="BuildAllConfiguration.vcxproj"/> 
<ItemGroup Label="ProjectConfigurations"> 
    <ProjectConfiguration Include="Debug|Win32"> 
     <Configuration>Debug</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Release|Win32"> 
     <Configuration>Release</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Debug|x64"> 
     <Configuration>Debug</Configuration> 
     <Platform>x64</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Release|x64"> 
     <Configuration>Release</Configuration> 
     <Platform>x64</Platform> 
    </ProjectConfiguration> 
    </ItemGroup> 
    <PropertyGroup Label="Globals"> 
    <ProjectGuid>{E6B6F967-3BE3-428F-9288-3F838B8E726A}</ProjectGuid> 
    <Keyword>Win32Proj</Keyword> 
    <RootNamespace>MyProject</RootNamespace> 
    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> 
    </PropertyGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 
    <ConfigurationType>DynamicLibrary</ConfigurationType> 
    <UseDebugLibraries>true</UseDebugLibraries> 
    <PlatformToolset>v140</PlatformToolset> 
    <CharacterSet>Unicode</CharacterSet> 
    </PropertyGroup> 
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 
    <ClCompile> 
     <PrecompiledHeader> 
     </PrecompiledHeader> 
     <WarningLevel>Level3</WarningLevel> 
     <Optimization>Disabled</Optimization> 
     <PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> 
     <SDLCheck>true</SDLCheck> 
    </ClCompile> 
    <Link> 
     <SubSystem>Windows</SubSystem> 
     <GenerateDebugInformation>true</GenerateDebugInformation> 
    </Link> 
    </ItemDefinitionGroup> 
... 
Similar Configuration Details for release and Platforms x64 

Ce fichier projet comprend BuildAllConfiguration.vcxproj

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <PropertyGroup> 
    <BUILD_PLATFORMS>Win32;x64</BUILD_PLATFORMS> 
    <BUILD_CONFIGURATION>Debug;Release</BUILD_CONFIGURATION> 
    </PropertyGroup> 
    <Target Name="BuildAll"> 
    <ItemGroup>  
     <CONFIGURATION Include="$(BUILD_CONFIGURATION.Split(';'))"/> 
     <PLATFORM Include="$(BUILD_PLATFORMS.Split(';'))"/> 
     <ProjectToBuild Include="$(MSBuildProjectFile)"> 
     <Properties>Configuration=%(CONFIGURATION.Identity);Platform=%(PLATFORM.Identity)</Properties> 
     <Targets>Build</Targets> 
     </ProjectToBuild> 
    </ItemGroup> 
    <Message Text="MSBUILD TASK input @(ProjectToBuild)"/> 
    <MSBuild Projects="@(ProjectToBuild)" /> 
</Target> 
</Project> 

Ce projet appellera MyProject.vcxproj avec Target Build et Properties qui ne sont pas correctement formatés. Mon attente est que les propriétés se passe comme suit

Properties=Configuration=Debug;Platform=Win32 
Properties=Configuration=Release;Platform=Win32 
Properties=Configuration=Debug;Platform=x64 
Properties=Configuration=Release;Platform=x64 

Au contraire, les propriétés sont passés comme suit

Properties=Configuration=Debug;Platform= 
Properties=Configuration=Release;Platform= 
Properties=Configuration=;Platform=Win32 
Properties=Configuration=;Platform=x64 

Répondre

0

Vous avez besoin d'un ici multiproduits, si vous recherchez que vous devriez trouver de nombreuses answers, mais je pense que si vous ne savez pas que ça s'appelle, ça pourrait être difficile à trouver. Quelque chose comme ceci:

<Target Name="BuildAll"> 
    <ItemGroup> 
    <CONFIGURATION Include="$(BUILD_CONFIGURATION.Split(';'))"/> 
    <PLATFORM Include="$(BUILD_PLATFORMS.Split(';'))"/> 

    <!-- cross product of both --> 
    <ConfigAndPlatform Include="@(CONFIGURATION)"> 
     <Platform>%(PLATFORM.Identity)</Platform> 
    </ConfigAndPlatform> 

    <ProjectToBuild Include="$(MSBuildProjectFile)"/> 
    </ItemGroup> 
    <MSBuild Projects="@(ProjectToBuild)" Properties="Configuration=%(ConfigAndPlatform.Identity);Platform=%(ConfigAndPlatform.Platform)" /> 
</Target> 

Quelques notes: les capitales rendent les choses plus difficiles à lire, peut-être ne les utilisent pas? De même, si vous placez vos configurations/plates-formes dans un ItemGroup au lieu d'un PropertyGroup, vous n'avez pas besoin de logique de fractionnement supplémentaire:

<ItemGroup> 
    <Configuration Include="Debug;Release"/> 
    <Platform Include="Win32;x64"/> 
<ItemGroup>