You have started writing your first Windows 8 Store app and now you are asking yourself, "Can I set up Continuous Integration (CI) for Windows 8 Store apps like I have done for other projects?" The answer is yes. By configuring CI for your Windows 8 Store apps, your apps can take advantage of immediate notification at compilation and unit test failures at each check in. There are a couple things that make Windows 8 Store app development unique that require a few steps to configure. I will walk through those unique items, show you how to configure the build machine, and show you the results of a successful build.
The TFS Build Agent typically performs the majority of the work during a Team Foundation Build process. Windows 8 Store apps require that the build agent be installed on a Windows 8 client or Windows Server 2012 machine. This also means that Windows 8 Store apps will not be able to be built using the Team Foundation Service Hosted Build Service. If you are using TF Service, one option is to use these instructions to configure a local Build Server and use it with the TF Service.
Unit Testing
Windows 8 Store apps include a separate project template for testing Windows 8 applications and class libraries. This project is designed to only allow valid Windows 8 assemblies and references. Additionally the unit test project can help validate the appropriate application capabilities are set by having a package manifest for the unit test project. Visual Studio 2012 Update 2 includes two improvements for unit testing in Windows 8 Store apps:
- [UITestMethod] – Decorate your test methods with this attribute to run on the UI Thread without having to write your own Dispatcher plumbing.
- Assert.ThrowException<T> method provides a more fluent way of writing unit tests that are expecting exceptions to be thrown.
More information on these features in Update 2.
Configuration
The following list contains the primary requirements for configuring a build machine to build and run unit tests for Windows 8 Store apps.
- Build Agent should be tagged with “Win8” or “Win8StoreApp”.
- Visual Studio 2012 must be installed on build server (Premium or Ultimate for Code Coverage).
- Build Agent must be configured to run interactively.
- Windows 8 Developer License must be installed.
- The Security Certificate for the Unit Test project must be installed.
Install and Configure Build Agent
First, install and configure the TFS Build Service on your selected Windows 8 or Windows Server 2012 build machine. Use the following article, Install Team Foundation Build Service to install and configure the Build Service. Once the Build Service is configured, open the build agent properties from the Team Foundation Server Admin Console and add a new Win8 tag to ensure that the application is built by the appropriate build agent if you have multiple agents configured.

Install Visual Studio 2012
In order for Windows 8 Store apps to build, Visual Studio 2012 must be installed. If you want to capture code coverage results, install the Premium or Ultimate editions otherwise you can install the same edition you are using to develop.
At this point, your Windows 8 Store apps will successfully build on the server. We will perform the remaining steps to configure the build machine for testing.
Run Build Service Interactively
The Windows Store app unit tests must be able to interact with the desktop. This requires the build service to be configured to run interactively or else you will get the following error:

To configure the Build Agent to run interactively, log into the machine as the user you want the build to run under. This can’t be Network Service. The build service user must also:
- Have administrative permissions on the build machine
- Be a member of the Team Foundation Server build service account group
- Have Change and Read permission to the drop folder identified in any build
Open the Team Foundation Server Administration Console. Under Build Configuration, stop the build service and then open the Properties dialog. Ensure the service is running under the appropriate user and check the Run the Service Interactively checkbox. Click the Start button and this will open a command dialog and specify the Build Agent is running in interactive mode.

Install Developer License
If you tried to run a Windows 8 Store app build with unit tests, it would generate the following error that there is no valid developer license found.

There are several methods for installing and managing Developer licenses see Get a developer license (Windows Store apps) for a comprehensive list. Here we will acquire it through PowerShell because I am currently logged in as the build agent user without a workspace configured to open the solution.
Run the Show-WindowsDeveloperLicenseRegistration cmdlet in PowerShell with elevated permissions. This opens the dialog below.

Agree to the license and it will prompt you for you Microsoft Account credentials to acquire the developer license. Once this has been installed, you will have a developer license for the next 30 days.
Now, if you were to try to run a build now, you would get a certificate error from the unit test project.

Install Unit Test Certificate
As the message above shows we next need to install the Unit Test project’s certificate on the machine so it will be trusted. You can install the .PFX file that is located within the Visual Studio project, but it is recommended that you install .CER certificate file. There are several ways to generate a .CER file. In this example, we will create the .CER file by creating the Unit Test project’s App Package. From your development machine, open the solution and right click on the Unit Test project (not the Windows Store app project) and select Store > Create App Packages.

The Create Your Packages wizard will open and ask you if you want to upload to the Windows Store. Choose no because we just want to create a local package to get the .CER file. Next keep the defaults but verify at least one architecture is selected. Click the Create button to initiate the building of the Unit Test project’s app package. Once it has completed, the dialog will include the link to the files. Click on this and open the appropriate version’s folder. Within the folder, there are several files including the Security Certificate file (.CER).

Copy this file to the build machine. From the build machine open a command prompt window with elevated permissions. Run the following command to install the certificate to the local store.
Certutil –addstore root your_unit_test_project.cer
When this has completed, it will display that the command has successfully completed. This completes everything you need to configure a Team Foundation Build Machine capable of compiling and running unit tests for Windows 8 Store apps.
Creating the Build Definition
Now that all of the requirements for building Windows 8 Store apps has been met, let’s create a CI build definition to verify everything has been correctly configured. In general, the build definition is similar to other CI build definition. There are a couple differences highlighted below.
Create the build definition by choosing New Build Definition by selecting the option in the Builds tab of Team Explorer. Under the Trigger tab, choose Continuous Integration for the build to run after each check-in. Next, in the Workspace tab, ensure the appropriate node is selected. This is typically mapped at the Team Project or branch level. In the Build Defaults tab, enter a network share where the output can be copied at the end of the build definition.
Within the Process tab, you will select the Windows 8 Store apps to build (if the solution was open when you created the build definition it will automatically populate as the solution to build. Next you need to change the Automated Tests search path to be **\*test*.appx to match the special extension of the Windows 8 Store app unit test project. Also, you will need specify the name of the tag you used when configuring the Build Agent. In my instance, I used Win8.

Save the build definition. To manually trigger the build, right click on the definition and select Queue New Build. Keep the defaults and click Queue to start the build. If your Windows 8 Store app includes a unit test project it will automatically execute the unit tests and report the results back to the build summary. After the build completes, the build summary should look similar to this.

Whether you are building Line of Business (LOB) Windows 8 Store apps or working on the next million dollar app idea, you can now utilize the benefits of Continuous Integration with Team Foundation Server and Team Foundation Build.