In yesterdays post I’ve shown you how to set up Continuous deployments of Xamarin Android apps to Hockeyapp. Today we’ll focus on Windows 10 UWP apps since this process is a bit more complex.
This post is part of a series of 3 blogposts:
- Windows 10 UWP (this post)
The basic process of setting up the continuous deployments is the same for all platforms: first build the sources, create a release and send that to Hockeyapp. However building the UWP app and sending it to hockey app require a few steps that aren’t so obvious. so lets start deploying
Context: the app we are going to deploy
We’re going to deploy the same app as yesterday in the Xamarin Android post. I’ve created a simple solution in Visual Studio containing an average Xamarin project. 1 PCL, 1 Android app, 1 iOS app and 1 Windows 10 UWP app.
This solution is checked into my GIT repository stored in VSTS so lets move to there to start building the UWP app today. please note that this also works for regular UWP apps that do not have any Xamarin involvement. it’s actually easiest to create a new solution containing only your class libraries (can be PCL) and your UWP project leaving out the Android and iOS specific projects (if you have any)
Setting up the build in VSTS
in VSTS open your team project and go to the BUILD tab. in here we’re going to create a new build definition by clicking the green + sign.
Choose the Universal Windows Platform build template and click next.
Select the repository containing the solution and select the branch you want to deploy. you can even choose to build apps that are stored in different sources such as GitHub or remote Git repositories.
After everything is set click on Create
A build definition will be created and several build steps are generated for you. We’ll go over them one by one.
but first we need to set some other things up. UWP apps can run on both Mobile devices and tablets or pc’s. this will need different builds focussing on either ARM or the x86 architecture. We’ll set up 1 build definition that will handle both.
To make sure the build runs for each platform we go into the options tab of our build definition and select “Multi-configuration”. set the multipliers to “BuildPlatform” so the build will run for each different build platform we select.
Next go to the “Variables” tab and set the “BuildPlatform” variable to both x86 as ARM
Back to the build steps. We’ll start with restoring all nuget packages. this step was automatically generated and we only need to set the correct solution. set this to the .sln file that only contains the UWP related projects.
Next step is building the projects in the Visual Studio build step that is already created for us. Set the solution to the solution containing the UWP projects and set the platform to the $(BuildPlatform) variable
If you’ve read the Xamarin Android guide as well you might expect what is the next step: publishing the artifacts. but here is when Windows 10 UWP apps start to be different from the Xamarin Android guide.
Hockeyapp does not have any option to upload .appxbundles that contain both ARM ad x86 sources. we need to split them up into 2 packages and then send them to Hockeyapp separately. for Windows 10 Mobile we can still upload an .appxbundle file but for Windows 10 tablet/desktop (x86) we need to send a .zip file containing the .appxbundle, the .cer file and the .ps1 file to install the app on the pc or tablet (installing is currently still manually running the .ps1 file for Windows 10. I hope and expect this will become better in the near future.
To be able to publish both the artifacts: .appxbundle as the zip file we need to remove the predefined step called “publish build artifacts” and replace it with another. We’ll also be removing the “Index sources & publish symbols” step.
Now it’s time to add 3 new steps. 2 powershell tasks (1 at the top of the build and 1 at the bottom) and after that a “copy and publish build artifacts”
Wait! Powershell? You would expect for Windows 10 UWP that everything would work out of the box. Well it isn’t currently so we have to do some parts manually.
The First powershell script we will add to the top will increase the version number of the Windows package to a unique number so Hockeyapp will understand new incoming versions. The version number always contains 4 digits:X.X.X.X where I would like to keep the first 3 digits up to the development team to clearly define their releases. the last digit we’re going to use for our release number. This version number is stored within an XML file in the project so we’ll open it, increase the number and save it so the build will use this new number. We’ll insert the BuildID as the last number since this is a unique number and an integer.
You’ll need to store the powershell code below in a .ps1 file and store it somewhere in your repository.
to make it easier I’ve already created all 3 powershell scripts you are going to need during this guide and stored them on Github. so you can also download them from there so you always have the newest version. Check them in to your own repository so you can use them in the powershell task.
In the powershell step select the UpdateAppVersion.ps1 and for arguments make sure you set 2 parameters. –projectFolder pointing at the directory where your AppxPackages will be created and the –buildId that points to $(Build.BuildId) So now this powershell script will change to build number and the Visual studio Build step will take this number into account and will version your appxpackage folder. next step is to create a .zip file of Appxpackage directory. again with powershell. ZipAppxPackage.ps1Select the ZipAppxPackage.ps1 as the script filename and pass a parameter called –dir to the script that has $(Build.BinariesDirectory) as its value.
so now everything is build and zipped and we can send it to the drop folder. our last step of the build.
Set the copy root to the $(Build.BinariesDirectory)\ and set the contents to copy to both *.zip files as *arm*.appxBundle files. The artifact name and type are set to drop and Server.
This was the final step of our build. you can run the app and everything should work. on to the next step: deploying to Hockeyapp
Setting up Hockeyapp
I assume you’ve already created an account at Hockeyapp otherwise just sign up at www.hockeyapp.net (It’s free for 2 apps or less) once you’ve logged in go and create your first app by pressing the New App Button
Hockeyapp will ask you to upload a build. we’re not going to do that since we’re setting up automatic deployments. choose to add the app manually
Choose Windows as a platform and fill in your release type and title of the app. Note that this is only the tablet/pc (x86) release of the app and not the ARM version.
Repeat the steps above for the Windows 10 mobile (ARM) version but then select Windows Phone as plataform
Copy the AppID of both apps and save them:
To be able to deploy from VSTS we need to set up an API token we can use in VSTS. If you already followed the Android guide you might have already taken these steps so you can skip these steps and move to the chapter of deploying the app.
Click on your user icon in the top right and select API Tokens from the menu on the left.
Create a new API token and call it VSTS. Copy this API token. we’ll need it in VSTS
Move back to VSTS and open up the marketplace (top right next to your name) and click manage extensions. browse the marketplace and install the Hockeyapp extension
After installing the extension go back to your VSTS team project and navigate to the settings window. in the settings menu go to Services and add a new service Endpoint of type “Hockeyapp”
Give the endpoint a proper name and copy in the API token you’ve generated earlier. now save the service endpoint.
Now all the plumbing with Hockeyapp is done we can actually start deploying our app to hockeyapp
Deploying your automated build to Hockeyapp
Go back to your team project in VSTS and navigate to the Release tab
Choose an Empty deployment template and press OK.
First go to the Artifact tab and select the build we’ve created earlier as supplier of the artifacts we’re going to release to hockeyapp.
Go back to Environments, name your deployment template and add a new Task
This list should now contain a Hockeyapp step since we installed that as our extension
This hockeyapp step will only work for Windows 10 Mobile (phone) and not for the pc/tablet (x86) version because sending .zip files is not supported by this step. we’ll cover this again by a custom powershell script.
Update: Hockeyapp made some changes to the Hockeyapp step in our deployment script so it can be used for both Windows 10 Mobile and Windows 10 Desktop/Tablet (x86/x64)
Windows 10 Mobile
To set up the hockeyapp step select the Hockeyapp connection you’ve set up earlier and enter your App ID. for the binary file path click on the … and select your ARM.appxbundle file
This step should do the trick. Schedule a release and you should be able to see a new version pop up in Hockeyapp.
Windows 10 (x86) Tablet/PC
For the Windows 10 (x86/x64) Tablet/PC version of the app we can now also use the hockey app build step so add another task of type Hockeyapp but let this one point to the other App ID for the Windows 10 desktop/tablet app and as Binary File path select the Zip file we created during the build instead of the appxbundle. Hockeyapp will see if there is already a version created and otherwise it will create a new version and upload it.
Now save the release definition and test it. press the green + to create a new release to see if everything works. if everything works fine go to triggers and set the build to continuous deployments so it will fire every time a new build is created.
Hopefully this guide helps you into creating higher quality apps and will save you time by not having to manually create releases all the time.
If you have any questions contact me on twitter @geertvdc or leave a comment below.
Happy Coding & deploying!