In this article I’ll show you how you can easily build Windows Store apps using PowerShell, without launching Visual Studio. Specifically how to build signed .appxupload packages that can be uploaded to Dev Dashboard straight away.
First some summary, by Windows Store apps I mean Windows 8, Windows 8.1, Windows Phone 8.1 (XAML) or Windows 10 (UWP) apps. All these apps use .appx package format when building in Debug mode in Visual Studio.
When creating Windows Store package for your app, you typically use these steps:
1. First, if not done previously, you need to Associate App with the Store. Before you can do that you need to login to Visual Studio with your Windows Store Microsoft Account using two factor authentication, typically using verification code on phone or sent to you by email. After that in the first step unique app name is reserved, app name, publisher name and publishers’ signing .pfx certificate is downloaded to you solution and these data are set in your Package.appxmanifest file.
2. Then you need to build the package for Store, this is typically done using the Create App Packages command. In the wizard that shows up it’s possible to select target version, bundle option, architecture and solution configuration and option to include debug symbols. After then the solution is built and packaged.
As you can see this is not exactly easy to do and definitely not suitable for automatic builds on your VSO or TeamCity Continuous Integration server.
Since Visual Studio 2013 I was trying to replicate the process that Visual Studio is doing when building app to Store using the Create App Packages Wizard. From what I found this process consist of several steps:
- msbuild.exe builds the solution in Release mode.
- makeappx.exe creates .appx package based on a map file containing list of all required files.
- signtool.exe signs the appx with my private pfx certificate.
- pdbcopy.exe copies all PDB files related to all dll, exe or winmd libraries without private symbols.
- These PDB symbols are zipped into .appxsym file.
- Signed .appx file together with .appxsym is zipped into .appxupload final file.
Details about these steps are described in this nice article: Create a Windows Store AppX package and sign it
I spent about two days packing all these steps into single PowerShell script file but then I made huge discovery – that when building Windows Store app in Release mode using Visual Studio 2015 msbuild, it automatically builds signed .appxupload file for the Store as well!
I was testing the same commands about year or two ago with Visual Studio 2013 and I am almost sure that VS2013 does not create .appxupload packages just like that.
To sum it all up, what to do to build Windows Store packages using PowerShell? First associate your app with Store using Visual Studio, select your preferred Store package configuration and build the packages at least once using the wizard. After that make sure to save all your changes to the solution and project file. These project settings will be then automatically used when building the solution using PowerShell. Then just grab this script, enter you solution name, run it in the folder with your solution and you are done 🙂
# tools $msbuild = "C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe" set-alias msbuild $msbuild # solution settings $sln_name = "TestSolution.sln" $vs_config = "Release" $vs_platfom = "x86" # call the rebuild method Write-Host "Building solution`n" -foregroundcolor Green msbuild $sln_name /t:Build /p:Configuration=$vs_config /p:Platform=$vs_platfom /v:q /nologo
What is even better about this – you can build Store packages without entering your Microsoft Account credentials every time. Note in my case I’m not using appx bundle settings and I need to repeat these steps for ARM and x64 Configuration.
After that only two unsolved tasks remain:
- How to run Windows App Certification Kit from PowerShell and display the results in TeamCity/VSO?
- How to upload the .appxupload package to Store automatically and release it as a new beta version of my app?
The first task might be possible, I’ll try to dig into this soon and post my findings in another article.
The second feature is still not available since there is no public Windows Store REST API for gathering data about apps from Store/Dashboard or publishing new beta builds automatically. If you think just like me that this should be implemented, please vote here in WPdev UserVoice web for this idea, thanks!