Click here to Skip to main content
14,972,891 members
Articles / Programming Languages / C# 5.0
Article
Posted 31 Jul 2015

Stats

25K views
149 downloads
5 bookmarked

Deploy Sideloaded Windows 8 App in Production

Rate me:
Please Sign up or sign in to vote.
4.68/5 (6 votes)
31 Jul 2015CPOL10 min read
Through this article, you will learn how to deploy the sideloaded Windows 8 app to production easily and maintain/provide regular upgrade version of the app.

Introduction

Sideloading: Sideloading simply means installing a Windows Store app without publishing it in and downloading it from the store. You install it directly. Basically, they are line of business (LOB) apps. It means the stack holders do not want to publish the apps through the Windows Store since that would make the apps publicly available.

Background

I have been working on a Windows 8 app which will be sideloaded to client’s tab. The tab is running on Windows 8.1 pro. I had to sideload the app and provide upgrade packages as bug fix and feature improvement. While working with all this stuff, I learned a few things that I have decided to share because I found it very difficult to get all the required information for sideloading app. Here are the steps that I followed to complete the deployment.

Step by Step Deployment Process

Step 1 - Allowing All Trusted Apps to Install on a Client's Machine

To install your app on client’s machine, you have to enable that feature. To do so, you need to change the following registry key’s value from 0 to 1. HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Appx\AllowAllTrustedApps = 1

Step 2 - Creating Own Signed Certificate and Package Key

You must change the certificate date to a maximum one and the publisher name to an appropriate one. For an instance, you might think that why do we need the certificate as Visual Studio already generates it for me? Okay, Visual Studio generates the certificate for you, that is true. But Visual Studio also sets expiry date that is usually a year. So what will happen if the expiry date is over? Will the app run properly or it won’t run? My finding is that the app will run properly but you won’t be able to install a new version or upgrade the app. So unless you change the certificate to the client’s tab or device, you won’t be able to install/upgrade anything to that device. So change them at the first hand. Here are some screenshots of what I am talking about.

Image 1

Image 2

In the above screenshots, you will find the Package.appxmanifest file, double click on the file and navigate to the Packaging tab. There, you will find the Package name and Package family name. If you change the Package name, the Package family name will be changed accordingly. This Package family name can’t be changed once it is set. You will find all necessary DLLs and other files to run your app with that folder name in the C:\Program Files\WindowsApps\Package family name folder.

On the right side of the Publisher tab, you will find the Certificate button. Click on that button and you will find a certificate with some Publisher name (by default, it takes the PC’s admin user name) and expiry date of a year. We need to change this expiry date. I described the reason above why we need to do that.

You will need two EXE files to create your own certificate file and package key file signed by your own password. They are makecert.exe and pvk2pfx.exe.

You might find the makecert.exe file in the following location: C:\Program Files (x86)\Windows Kits\8.1\bin\x64

And pvk2pfx.exe in the following location: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin

Location might not match as the version of Visual Studio running on your device may not match. I am running Visual Studio 2013 on my laptop for development. So you need to do some work to find them. I have also attached the EXE files with the article.

Now we need to start creating certificate and package key for our project.

  1. Create a folder in the C drive called MakeCert and place those two EXEs there and run the following two commands on the command prompt:
    • C:\MakeCert>makecert -sv CodeProjectApp.pvk -n "CN= CodeProject" /r /h 0 /eku "1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13" CodeProjectApp.cer -b 05/07/2015 -e 05/08/2030 -r
    • C:\MakeCert>Pvk2Pfx -pvk CodeProjectApp.pvk -pi CodeProjectApp -spc CodeProjectApp.cer -pfx CodeProjectApp_PermanentKey.pfx -po CodeProjectApp –f

** Here, CodeProjectApp is the password. CodeProjectApp.cer is the certificate file name.

In the project explorer, you will find a temporary Personal Information Exchange file or .pfx file named CodeProjectApp_TemporaryKey.pfx that pfx file contains all the necessary information for this project. We will replace that file with our new CodeProjectApp_PermanentKey.pfx file. To do so, click on the Choose Certificate button and select the file we now created on C drive. Now the project’s certificate will expire after the year 2030.

But that’s not all we need to install the certificate separately to keep match with the app. To do this, please follow the steps below:

  1. Right click on the CodeProjectApp.cer file -> Choose install certificate -> Local Machine -> Next -> Place all certificate -> browse -> Select Trusted Root Certification Authorities -> Ok -> Next -> Finish.
  2. To be sure about expiry date and that the certificate is properly installed, do the following:
    1. Press Windows Key + S and type Manage User Certificates. Then, expand Trusted Root Certification Authorities -> Certificates. There, you will find the certificate you just installed. Double click on the certificate to see expiry date.

** The certificate installation process is for the client PC where the release version of your app will run.

** You need to install the sideloading key and activate sideloading to your client’s PC to successfully install and run the app. To get the sideloading key, you have to communicate with the Microsoft’s representative to get key.

Here goes the Microsoft’s guideline link for getting sideloading key. (https://technet.microsoft.com/en-us/library/dn613835.aspx)

About Sideloading

You can enable sideloading for these scenarios by using the Windows Software Licensing Management Tool (Slmgr.vbs) and performing the following steps for each targeted device:

  1. Obtain a sideloading product activation key for the device. For more information about how to obtain a sideloading product activation key, see the Windows 8 Volume Licensing Guide.
  2. Add the sideloading product activation key to the device by running the following command from an elevated command prompt (where <sideloading product key> is the 25-digit sideloading product activation key):

    Slmgr /ipk <sideloading product key>

  3. Activate the sideloading product activation key by running the following command from an elevated command prompt:

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

Step 3 - Creating App Bundle Package for Deployment

Now it’s time to create the app bundle package:

Steps

  1. Create app package for CodeProjectApp app. Select CodeProjectApp Project, then choose Project option from Visual Studio menu, then -> Store -> Create App Packages -> No -> Check the version number -> Generate app bundle (Choose Never) -> Check x86 -> Create -> it will take some time to create the app package, once done, it will show a window which will contain the package folder path link (you can click on that path to go to the package folder directly. This package folder contains the .appx file “Dependencies” folder) -> Close.
  2. For the version number, the upper version number usually works as upgrade version of the app. So to upgrade the app manually, all you need to do is to create an app package with a higher version number than the installed version and then just install the app again. For example, if the installed app version number is 1.0.0.1, then 1.0.0.2 will work as the upgrade version if you install the new version. In that case, the database will remain as it is. The version having the upper build numbers don't change or remove the database files and other resources. You also have to keep in mind that the lower version will not be the installed of the higher version of the app is already installed on that machine.

** The latest version will act as the upgrade package if the package family name (our project’s package family name is CodeProjectApp_763n4ec54fjwc) remains the same for both installed version and new version. If their package family names differs, then a newer version will be installed. Usually, the installed folder also contains the version number. For example, CodeProjectApp_1.0.0.1_x86_763n4ec54fjwc will be the installed folder name.

We have already generated the .appx file now we have to install the .appx file with powershell. I have created an EXE which does all this work for me. I have attached the source code for this task. Please follow the steps to install the app with C# code and powershell.

First of all, you need to get access of using the powershell as the user of the device may not have the proper access to install or upgrade the app. To do so, I did the following:

C#
private static void PreparePowerShellPermission()
{
   using (PowerShell powershell = PowerShell.Create())
   {
      powershell.AddScript("Set-ExecutionPolicy RemoteSigned -Scope CurrentUser");
      IAsyncResult result = powershell.BeginInvoke();
      Console.Write("\nWaiting to get access permission of CurrentUser");
      while (result.IsCompleted == false)
      {
        Console.Write(".");
        Thread.Sleep(2000);
      }
      Console.Write("\n");
      Console.Write("-Access granted!\n");
   }

   using (PowerShell powershell = PowerShell.Create())
   {
      powershell.AddScript("Set-ExecutionPolicy unrestricted");
      IAsyncResult result = powershell.BeginInvoke();
      Console.Write("\nWaiting to get permission of PowerShell");
      while (result.IsCompleted == false)
      {
        Console.Write(".");
        Thread.Sleep(2000);
      }
      Console.Write("\n");
      Console.Write("-Access granted!\n");
   }
}
C#
private static string Execute(string scriptPath)
{
    const string shellPath = @"powershell.exe";
    var sb = new StringBuilder();
    sb.AppendFormat("\"&Add-AppxPackage '{0}'\" ", scriptPath);
    string result = ExecuteCommand(shellPath, sb.ToString());
    return result;
}

** Here, scriptPath is the .appx file location.

** This is my way of coding according to my requirements. Please modify it according to your own requirement.

Here is an important link that I got useful help:

Upgrading Windows 8 App

Suppose you don't want to use Windows Intune or System Centre Configuration Manager to install or upgrade your app. So is there really any way to do that? The answer is YES, there is. I have already shown the installation process. Here is the easiest way to upgrade the app.

Steps

  1. Suppose you have an ftp server where you have an upgrade package. The upgrade package version no is 1.0.0.2 where the installed package version no is 1.0.0.1.
  2. Now suppose you have an option in your app to upgrade the app. Say the button name is Upgrade App. Once the Upgrade App button is clicked, all you need to do is to download the package file/ zip file containing the package file (.appx file) then open an external application to launch a console application from your app. Here is the code to launch an external application from a Windows 8 app.
    C#
    public async void LaunchExternalUpgraderApplication()
    {
      try
      {
         StorageFile file = await StorageFile.GetFileFromPathAsync
             (Path.Combine(ApplicationData.Current.LocalFolder.Path, 
              @"ExternalApplicationExtensions\ExternalApplication.ExternalApplicationExtension"));
         Launcher.LaunchFileAsync(file);
      }
      catch (Exception exception)
      {
         //
      }
    }

    ** Here, ApplicationData.Current.LocalFolder.Path = "C:\Users\YourUserName\AppData\Local\Packages\CodeProjectApp_763n4ec54fjwc\LocalState"

  3. Create a folder named ExternalApplicationExtensions in your LocalState folder and create an empty file with extension ExternalApplicationExtension. So the file name will be something like ExternalApplication.ExternalApplicationExtension.
  4. Upgrading process is the same as the installation process. So, use the above code to create a console app that will let you run the upgrader automatically. Then, place that console app anywhere on the disk and set this console application as the default program executor of the ExternalApplication.ExternalApplicationExtension file. To do this, right click on this ExternalApplication.ExternalApplicationExtension file and set the default program as that console app we just created. Now, once you will launch this extension file, your console app will be run and do the job for you. Ta Da!

Points of Interest

During the development and R&D stages, I learned a lot of things about the deployment process of sideloaded Windows 8 app. I have described the scenarios I faced so far. If you want to manage your upgrade versions of your app by your ftp server without using Windows Intune or Windows System Centre Configuration Manager, you can also do that. In that case, you just have to maintain your versions from Package.appxmanifest file and deploy using your own code. I described a way of doing this above. If you have anything, please share with me. I will be very pleased to do some R&D on that.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

dpalash
Software Developer Cefalo
Bangladesh Bangladesh
Hi,

I am Palash Debnath. I have been working on windows technologies since 2008. I started with ASP.NET. Then I moved to Windows Form and from the last year I have been working with Windows 8 app development. Work with Windows 10 apps development as well. Now I have been working with Microsoft Azure. I have completed my Undergraduate from Khulna University of Engineering in Computer Science & Engineering. Currently working as a Senior Software Engineer at Cefalo.

Comments and Discussions

 
QuestionPackage Family Name changed with new code signing cert Pin
jilanisk0911-May-16 20:53
Memberjilanisk0911-May-16 20:53 
AnswerRe: Package Family Name changed with new code signing cert Pin
dpalash8-Jun-16 3:37
professionaldpalash8-Jun-16 3:37 
Questionnice Pin
Member 105108222-Aug-15 17:36
MemberMember 105108222-Aug-15 17:36 
QuestionNice Post Pin
Fiyaz Hasan1-Aug-15 11:38
professionalFiyaz Hasan1-Aug-15 11:38 
AnswerRe: Nice Post Pin
dpalash1-Aug-15 19:36
professionaldpalash1-Aug-15 19:36 
GeneralVery good article Pin
Md. Faruk Hossen Khan1-Aug-15 8:37
MemberMd. Faruk Hossen Khan1-Aug-15 8:37 
GeneralRe: Very good article Pin
dpalash1-Aug-15 9:22
professionaldpalash1-Aug-15 9:22 
GeneralMy vote of 5 Pin
Monjurul Habib1-Aug-15 8:06
professionalMonjurul Habib1-Aug-15 8:06 
GeneralRe: My vote of 5 Pin
dpalash1-Aug-15 8:10
professionaldpalash1-Aug-15 8:10 
Generalvery nice Pin
Harry K1-Aug-15 6:00
MemberHarry K1-Aug-15 6:00 
GeneralRe: very nice Pin
dpalash1-Aug-15 8:09
professionaldpalash1-Aug-15 8:09 
Generalvery nice Pin
Harry K1-Aug-15 6:00
MemberHarry K1-Aug-15 6:00 
GeneralMy vote of 5 Pin
Sk. Tajbir1-Aug-15 4:38
MemberSk. Tajbir1-Aug-15 4:38 
GeneralRe: My vote of 5 Pin
dpalash1-Aug-15 5:03
professionaldpalash1-Aug-15 5:03 
Generalimages don't show up Pin
Southmountain31-Jul-15 9:48
MemberSouthmountain31-Jul-15 9:48 
GeneralRe: images don't show up Pin
dpalash31-Jul-15 19:23
professionaldpalash31-Jul-15 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.