TeamBuild - Is it possible to choose what projects to compile at build-time?
-
03-07-2019 - |
Question
I am automating my build process using TeamFoundation and I need to choose what projects to compile according to the .proj file from the build. Here is the full scenario:
I have a .proj file which uses a .sln file in order to compile a solution which contains 2 websites. The .sln file is configured to compile both websites in Release configuration.
My goal is to compile only 1 website per build type, namely I want the BuildType1 to compile website 1 and BuildType2 to compile the website 2.
Is is possible to "modify" the .sln in such a way that I can unmark one of the websites to compile? Since it is an automated process, I can't change the .sln manually every time I want to compile only one website.
Solution
Look at the SolutionToBuild section in the TFSBuild.proj file.
<SolutionToBuild Include="$(BuildProjectFolderPath)/path/MySolution.sln">
<Targets>MyCustomTarget1;MyCustomTarget2</Targets>
<Properties> Configuration=Release</Properties>
</SolutionToBuild>
OTHER TIPS
There are two main ways you can control the build:
create a separate Build Type in your Team Explorer. This will have its own completely independent TFSBuild.proj file, so it can build the same code-base in a completely different way. Set the SolutionToBuild up to build just what you want (as described in the accepted answer).
Use one Build Type, and set its TFSBuild.proj up to use a property to control what is built (this requires more in depth understanding od MSBuild scripts). In the Queue New Build dialog you can then use the /p: command line flag to set the property as you need it. e.g. "/p:IncrementalGet=false;IncrementalBuild=false;ForceGet=true" will force a normally incremental build to do a full rebuild. This is useful for occasoinal situations, but not a good idea for day to day builds as you have to set the parameters by hand every time.