Team Foundation Server had introduced Build Automation right from its very first release i.e. TFS 2005. At that time, the build process was based upon MSBuild technology. There was a major change in Build Service with the introduction of Visual Studio 2010 and Team Foundation Server 2010. Microsoft also introduced a very useful trigger called as Gated Check-in. The newly introduced build process was completely XAML based. This approach was followed until Visual Studio 2013. The XAML build definition could be created with the help of a wizard and it was a straight forward process if you didn’t need any customization. Any customization could be done by customizing the default workflow, editing it, as required. We could create a new activity either by using XAML or by writing code and implementing it in a customized process template.
This article is published from the DNC Magazine for .NET Developers and Architects. Download this magazine from here [Zip PDF] or Subscribe to this magazine for FREE and download all previous and current editions
All this required the knowledge of XAML workflow as well as handling the problems and limitations of the XAML builds, one of them being builds being able to run on-your-machine but not on the Continuous Integration server. Team Foundation Server 2015, brings a major improvement in the build service. The new build runs on a different architecture and also runs on a completely different system. You can still use your XAML builds along with your new builds, controllers and agents.
In this article, we will discuss the new build features available with Visual Studio 2015/TFS 2015 and Visual Studio Online.
Working with TFS 2015 Build
- You do not need to create build, you can add steps for MSBuild, Ant, Maven, PowerShell etc. (readymade templates are also provided)
- You can build cross platform solutions
- You can create custom activity with open source activities
- Live console view is available
We can use either Visual Studio Online account which will give us hosted build controller or on-premises Team Foundation Server 2015 with which we can configure default build controller.
With Visual Studio 2015 you can build for any platform (Windows, iOS, Android, Java or Linux). Just open your browser and start creating and triggering builds.
Visual Studio 2015 shows two different build definitions you can work with - New as well as XAML build definition. The screenshots attached are with Visual Studio 2015 as well as from Visual Studio Online (termed as VSO)
Figure 1: Build Explorer from Visual Studio 2015
The new Build System with Visual Studio 2015
The new builds are script based and web based. To build Windows, Azure, and other Visual Studio solutions, you need at least one Windows build agent. This agent can be a part of an agent pool which can be created by going to Administer Server tab > selecting Collection > and later Build tab from it. A new pool can be created for registering agents. Pools are available to run builds for all collections. The collection name can be specified while configuring the agent.
It is possible to manage agent pools (a groups of resources or agents), download and configure build agents by selecting the administer account from Web Access. Make sure the path for download is not too long.
Figure 2: Manage Pools via Web Access
We can configure agents for on-premises Team Foundation Server, as well as for VSO. Figure 2 shows the hosted agent is configured. There is a link for Download Agent. Once the agent is downloaded, configure it by starting PowerShell as Administrator. In the downloaded folder, you will see a PowserShell script file named ConfigureAgent.ps1. Start this script from PowerShell command prompt. It will ask for various configuration related questions like name of agent (default), url for Team foundation Server, name of the pool (default) and how the agent should be running. We can run build agent as an interactive process or as a service. We can create pool as default or hosted, depending upon if we are using VSO or on-premises TFS.
If I select Manage pool, I get two groups - one for Agent Pool Administrators and other for Agent Pool Service Accounts. Administrators operate as a role, if any user is added to the Admin group, he/she can add or remove agents. Service accounts is to allow for agents to connect to the pool.
There are some restriction for using hosted pool (with VSO) though. Following are the scenarios where hosted pool will not be available:
- You are running XAML builds
- You need multiple builds to run for your account
- Build process is a long time process (takes almost more than an hour)
- Build process uses lot of disk space on build server (even more than 10 GB)
- You want to run build process in interactive mode
We can configure XAML build processes which are not migrated or want to keep as it is. For this, we have to use the ‘XAML Build Configuration’ tab shown in Figure 3 at the time of configuring Team Foundation Server, as we used to do in earlier versions. We can configure the build service to start automatically if required.
Figure 3: TFS Configuration wizard – Configure XAML Build
Creating a new Build Definition
Let us create a new build definition and see how it will be triggered. I have created a Team Project based on Scrum Process template and added it to TFVC (Team Foundation Version Control) for this walkthrough. Here are the steps involved.
Click on New Build Definition option from Visual Studio 2015 and you will get following screen as shown in Figure 4. It automatically takes you to Web access
Figure 4: Create Build via Web Access
2. You can create build for Windows, iOS, Ant, Maven or on Linux also as step(s). Add MSBuild step and provide the solution to be built. With Visual Studio Online definition, templates are also available. You can create your own templates too.
Figure 5: Add steps to Build
The Visual Studio Build task is added and the project to build is provided as shown in Figure 6.
Figure 6: Visual Studio Build Step with solution added to built
3. The build can be edited and customized by using script languages like batch script, PowerShell script or passing command line arguments.
Figure 7: Build Definition – Run Utility for customizing
4. We can add Build Verification Tests using Visual Studio Test or Xamarin Test Cloud
Figure 8: Build Definition –Adding Steps for Testing
5. If we select Visual Studio Online, we get more options for test tab. Note that we can run load testing as it is now supported with VSO.
Figure 9: Build Definition – Adding Test Steps using VSO
5. Now provide deployment options like Azure Cloud Service or Azure Web site
Figure 10: Build Definition – Add Deployment Steps
6. MultiConfiguration option from Options tab shown in Figure 11 helps in building selected solutions multiple times. We can add comma separated list of configuration variables here. These variables are listed in the variables tab. You can find a list of predefines variables at this link. If we click on the Parallel check box, it will have all the combinations provided in parallel. The pre-requisite is that there should be multiple agents available to run. If the variables are declared, we need to set the values for them. We can even provide multiple values to variables by separating with comma.
Figure 11: Build Definition – Provide multiple configuration facility
7. The next tab is for version control repository. You can choose TFVS (Team Foundation Version Control) or Git depending upon the project to build.
Figure 12: Build Definition – Adding repository from Source Control
8. There are two triggers available - Continuous Integration and Scheduled.
Figure 13: Build Definition – Provide Trigger for Build
The filter will allow to include * or exclude any string that starts with the filter criteria provided.
9. If we want to add more steps we just have to go back to Build tab and add the required one. The build definition can be saved as a draft which can be edited anytime later.
10. Retention tab is to decide how long the builds will be retained. These settings can be changed by choosing the option to administer server, select Collection, select Build and finally select Settings tab. History will provide options as Save, Queue Build, Undo and Diff. We can select two builds and click on Diff tab which will provide us with the differences between the two builds(similar to diff tool for version control)
11. Once the build is created and saved, it will be automatically triggered with next check-in because of Continuous Integration. The existing build definition can also be saved as a template. Such templates can be used as base for new definitions. The triggered build will be executed by default agent or hosted depending upon if we are using on-premises TFS or VSO.
Figure 14: Successful completion of Build
The build is successfully completed.
We can add tags to the build so that we can filter the builds later. We can also find out the changeset which triggered the build as well as retain any build indefinitely if needed. At the time of build execution the console will show us live results as shown in Figure 14.
12. We can add steps for testing with Visual Studio and also configure Code Coverage results. Following build covers Test results as well as Code Coverage information.
Figure 15: Build Completion with Test Results and Code Coverage analysed
Here’s a wrap up of some important features of working with Visual Studio 2015 Build
- It gives a Web User Interface. Even if we start creating a build definition from Visual Studio, we end up working with Web UI.
- Customization is simple. We don’t need to learn Windows workflow anymore.
- Cross platform builds are supported.
- With previous version of build, the build controller was configured to build service which in term was connected to a collection. Now we can create pools with agents.
- You can view complete logs. These logs can also be downloaded as zip file.
- If we have enabled Multiconfiguration and also have two build agents configured, we will be able to see parallel builds.
- If we select any task on the left hand side of the explorer, we can see build summary for that task (e.g. Get Sources, Build Solution, Test Assemblies etc.)
- Facilities like running Tests as Build Verification Tests or finding Code Coverage information are still available
The new builds are web- and script-based, and are highly customizable. They leave behind many of the problems and limitations of the XAML builds. Try it out and see the difference for yourself.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce the The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on .NET Standard and the upcoming C# 8.0 too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Purchase this eBook at a Discounted Price!