TFSBuild.proj File and Build Process Customization
TFSBuild.proj file is used to customize and tailor Build process according to our needs. One of the most useful and handy customization is configuration of the build execution plan. For example, you are working on a very large project that requires a long time to build and if you use continues build this will be a real problem to wait a long time for each build is complete upon each check in into source safe, so you may want to build only updated files versus entire project. TFS provides very handy functionality to do just that.
You need to update TFSBuild.proj file in order to build files that were changed. Following XML statement do just that. This XML code snippet needs to be added into the TFSBuild.proj file.
<Target Name="ShortBuild" Inputs="@(CSFile)" Outputs="$(AppName).exe" >
<CSC Sources="@(Compile)" OutputAssembly="$(AppName).exe" />
</Target>
<PropertyGroup>
<SkipClean>true</SkipClean>
<SkipInitializeWorkspace>true</SkipInitializeWorkspace>
<ForceGet>false</ForceGet>
</PropertyGroup>
Process of specifying only recently changed files for the build is called Incremental Build and can be very useful when large team is working on a large project.
SkipClean – removes files and folders before building the target.
SkipInitializeWorkspace – removes old workspace and recreates new one.
ForceGet – replaces source files with new files from the workspace.
In order to perform customization to the TFSBuild.proj file you need to follow very distinct steps. They are:
- Run tf add Custom.dll
- Run tf checkin Custom.dll
- Checkout and update TFSBuild.proj
- Save and checkin TFSBuild.proj
Another good example of utilizing TFSBuild.proj is when we need to add custom task that executes after project completed build. For instance, we could send an email that project build was done. In this case, we need to create custom task and store it in the CustomTask.dll, store this item under source control within the same node as team project and register our custom task with TFSBuild.proj file
<Target TaskName="SendEmail" AssemblyName="CustomTask" />
We also need to add custom task via the following XML code
<Target Name="AfterEndToEndIteration">
<SendEmail />
</Target>
We can start build process from the command line with the help of the command line tool called TFSBuild. In order to start up build process on the server we specify Server name, Project Name and target Build machine.
TFSBuild start http://TFSProject:8080 MyTeam MyProject /machine:TFSBuildMachine
Same line of code can be executed from within Windows Scheduler as explained above.
However, TFSBuild cannot be used if we want to remove Build Type from the TFS. We need to use Team Explorer to remove Build Type.
In order to perform Build Type removal, you need to navigate to the View many, click on Other Windows and select Source Control Explorer. In the folder pane, select the build type folder that you want to remove. Normally it is located under Team Project\Team Build Types\[Build Type Name]\ folder. After folder is selected choose delete from shortcut menu to remove build type entry.