3

I need to skip all projects which end to ".UnitTests" from build pipeline when I build it for ARM.

And I need to build it if I build for x86, but exclude other projects?

Is it possible to skip some projects from the build process by some kind of rules?

Viacheslav Smityukh
  • 5,652
  • 4
  • 24
  • 42
  • Interesting question, I'm also interested in an answer. Perhaps [this answer](http://stackoverflow.com/a/17712386/4534262) may help. Together with [this article](http://www.codeproject.com/Tips/177770/Creating-MSBuild-projects-from-sln-files). – Nikerboker Apr 18 '16 at 19:50

1 Answers1

2

The msbuild way of doing this would be to use the Configuration Manager (Build -> Configuration Manager) in Visual Studio to map the projects to the solution config/platform.

In the Configuration Manager:

  1. select ARM as the Active Solution Platform and uncheck Build for all the *.UnitTests projects and ensure the other projects have Build checked.

  2. select x86 as the Active Solution Platform check/uncheck Build based on which projects you want to build.

This will mean that whenever you build your solution for Platform=ARM, all the projects except for your *.UnitTests, will build. And similarly for Platform=x86.

You can read more about it here.

Update:

If you need more custom logic to choose projects to build, then you could create a new top level build file like:

<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup Condition="'$(Platform)' == 'ARM'">
            <ARMProjects Include="abc\*.csproj" Exclude="**\*.UnitTests.csproj"/>
            <ARMProjects Include="def\*.csproj" Exclude="**\*.UnitTests.csproj"/>
    </ItemGroup>

    <ItemGroup Condition="'$(Platform)' == 'x86'">
         <!-- Create a group named X86Projects and select the projects as you need to -->
    </ItemGroup>

    <Target Name="Build">
         <MSBuild Project="@(ARMProjects)" Targets="Build" Condition="'$(Platform)' == 'ARM'"/>
         <MSBuild Project="@(X86Projects)" Targets="Build" Condition="'$(Platform)' == 'x86'"/>
    </Target>
</Project>

Tweak the build targets or the projects selected according to your needs.

radical
  • 4,364
  • 2
  • 25
  • 27
  • That's probably helpful advice for some readers, but that's the VS way of doing this, not the msbuild way of doing this. – zeromus Apr 19 '16 at 09:50
  • I know it, but I'm looking for a way to change it on CI server on the fly instead of using static configurations. – Viacheslav Smityukh Apr 19 '16 at 10:02
  • @ViacheslavSmityukh On your CI server you could choose the configuration+platform to build via command line args: `msbuild /p:Configuration=Debug /p:Platform=x86` . If you want more custom logic to choose the projects to build, then you can will need a custom msbuild file which does that for you. I will update the answer to include that. – radical Apr 19 '16 at 14:30
  • @zeromus msbuild also supports the same thing. It parses the `.sln` file and generates a msbuild project file from that, based on the config+platform mappings found in the `.sln` file. You can select the config+platform for the build, from the command line. – radical Apr 19 '16 at 14:32