ClickOnce Deployment for Enterprise Windows Store Apps

Deploying and testing enterprise apps in a non-developer PC is tricky. This article provides a simple hack, so that developers can easily test their Windows store universal apps in other computers without much trouble. You should not be using this approach for deploying any production apps, instead you should use any of the following methods to deploy the production apps.

Through Windows Store:- If you want to target users both inside and outside of your organization.

Sideloading with Windows Intune:- If you want to target users within your organization.

Even though the article title is ClickOnce deployment, I would be taking a slightly different approach compared to the real ClickOnce.  I have a simple HelloWorld universal app here for demonstration, and I have added another Windows Forms project – HelloWorldInstaller to the solution.  HelloWorldInstaller will be responsible for installing all the prerequisites and HellowWorld  app to the target computer. I have added basic controls – to trigger the installation and show the installation status – as given below.

InstallerForm

Before diving more into the code of the installer, let us consider the steps involved in sideloading (deploying) the Windows Store app to target PC.

  1. We need the APPX package of Store app.
  2. The APPX package needs to be digitally signed with a certificate that is trusted by the target device.
  3. Update the group policy to allow trusted apps installation
  4. Sideloading has to be explicitly enabled in Windows.
  5. The edition of the Windows operating system on the device must be licensed for sideloading.
  6. Install the APPX bundle using PowerShell.

We will be doing above mentioned steps in the HelloWorldInstaller, so that end user can install the HelloWorld app with a single click ( ClickOnce).

Create App Package:- Select the HelloWorld Windows project, and go to project -> Store -> Create App Packages menu.   CreatePackage

“Do you want to build packages to upload to Windows Store?” – No

Select x86 release as show in the image, and create the package. Once you get the “Package Creation Completed” window, close the same and copy the output package folder location.

Bundle the APPX and Certificate files:- BundleAppxSelect the HelloWorldInstaller project, and appxbundle and certificate files.

Project->Add -> Existing Item, and select the package folder created earlier with “All Files(*.*) filter.

Note: If your app got any other dependencies (eg:- Microsoft.VCLibs.x86.12.00.appx), please add that as well.

BuildActionTo simply further, rename the files in Visual Studio to HelloWorld.appxbundle and HelloWorld.cert, and  set the build action to “Content” and Copy to Output to “Copy Always”. Now we have the Widows Store app bundle as part of the Installer build output.

 

Initialize: “Initialize” button click is required only once in a target computer, and subsequent app upgrade should be invoked by “install” button click.  We need to do the following actions during the initialize operation.

I have added a simple registry update script (GroupPolicy.reg) file as part of the project, and it should be invoked during the SetGroupPolicy call.

 HelloWorld.Cert should be added to the trusted root during the InstallCertificate method call.

I have also added another simple batch file to enable the sideloading and it is essentially doing the following steps.

Slmgr /ipk <sideloading product key>

slmgr /ato ec67814b-30e6-4a50-bf7b-d55daf729d1e

You should get the sideloading product key for your enterprise Windows licensing team.  Now we have done all the requirements related to initialization.

Installation:-  Once we have the appx bundle and target computer satisfy the above mentioned sideloading criteria, installation is straightforward using the PowerShell. Here comes the snippet from the install button handler.

Publish & Deployment:- Before deploying the Installer app in target computer, Please try it in local computer.  Run the Installer app, and click “Initialize” first, and then click “Install”, and you should see the “HelloWorld” app in Windows home screen under apps collection.

Now select the Installer project, right click the project and select publish, and select any FTP location. If you are using Windows Azure website hosting, download the publishing profile to get the FTP credentials.

Once you complete the publish, You should get the ClickOnce publish page, and you can share the same url with other users (beta testers / QA) in your organization.  In case of app upgrade, we should publish the updated installer, and next time user launches the installer it should automatically pull the latest appxbundle to the target computer.

Conclusion:- As you have already noticed, I am just automating the Enterprise app sideloading steps mentioned here, so that QA / Test engineers / beta users can install the app without much difficulties.

Entire source code can be located here in GitHub.