Search code examples
msbuildx86anycpu

Building all projects of a solution with a mixture of x86 and "any cpu" projects using MSBuild


Is it possible to be able to build all projects of a solution with x86 and "any cpu" projects in it from MSBuild?

Ideally I would like a solution that would work regardless of whether the project has multiple platforms or not because it's often not obvious when you add a project that defaults to x86 and you have to spend a lot of time figuring out why your project isn't being built.


Solution

  • If your solution has multiple platforms you want to target, it's possible to define multiple configurations to build in your tfsbuild.proj file:

    <ItemGroup>
      <ConfigurationToBuild Include="$(BuildFlavour)|Any CPU">
        <FlavorToBuild>$(BuildFlavour)</FlavorToBuild>
        <PlatformToBuild>Any CPU</PlatformToBuild>
      </ConfigurationToBuild>
      <ConfigurationToBuild Include="$(BuildFlavour)|x86">
        <FlavorToBuild>$(BuildFlavour)</FlavorToBuild>
        <PlatformToBuild>x86</PlatformToBuild>
      </ConfigurationToBuild>
    </ItemGroup>
    

    MSBuild and TFSBuild will build any projects that match either configurations.