Thursday, June 21, 2018

Converting a Windows MSI package to an APPX

  Introduction


    This article is a tutorial that will present to you all the steps required to take in order to convert a traditional Windows app into the Windows 10 app packaging format (APPX). Appx is a special type of software package format used by the Windows developers to put together code and resources and, finally, to submit for publication the program in Windows Apps Store.

   In fact, all the steps I will present here are the steps I have made to develop the blessTags application (Windows Store link - the only app able to manage 4 different SensorTags) and the blessTags Lite application (Windows Store link) – a free version of blessTags applications.

 

 Requirements:

  1. A computer with Windows 10 Professional or Enterprise operating system (OS);
  2. A  64 bit (x64) processor with support for: (a) Hardware-assisted virtualization and (b) Second Level Address Translation (SLAT)
  3. Desktop App Converter tool;
  4. The base Windows image;
  5. Windows 10 SDK;
  6. An existing installer (a MSI file) of your application – in a following post, I will present how to generate a MSI file, from the LabWindows CVI environment, able to work as an UWP application.

 Components installation:

  1. Update the windows. Desktop App Converter requires at least Windows 10 Anniversary Update to work - version 1607 (released on August 2, 2016; end of support: April 10, 2018; end of additional servicing: October 9, 2018).
  2. Install the Desktop App Converter tool itself, from the following link:
  1. Download the base Windows image. This package is used as a container and it is required in order to generate your AppX package. But, each type of Windows (each specific build like 17134, 16299, 15063 or 14393) needs to have a matching base Windows image for the Desktop App Converter to work correctly. As a result:
    1. First, find your Windows build version. Press Win + R keys together to launch the RUN dialog box and then type cmd and press Enter.
    1. From there, you can find the needed information – the build number: the number placed inside the red rectangle.
    2. From the following link download the base Windows image associated with your Windows build (this file is big, approximately 3.3 GB, be prepared to have enough free space on the HDD):
  1. Run Desktop App Converter as administrator (under administrative privileges): Press Win key → Desktop App Converter + click rightMoreRun as administrator (see the figure from below). 
  1. Bypass the standard Windows execution policies:
PS C:\Windows\system32> Set-ExecutionPolicy bypass
  1. Install the base Windows image, by executing the following command:
PS C:\Windows\system32> DesktopAppConverter.exe -Setup -BaseImage "D:\Windows_BaseImage_DAC_17134.wim" -Verbose
  1. A container is the equivalent of a virtual machine; a virtual machine of a specific type sustained by the fewest number of components from the Windows operating system. So, a container = a "little" virtual machine. Containers enable you to execute an application in an isolated environment. In order to build an APPX, you will need the windows feature “Container”. So, you have several options to install “Containers”:
    1. If in the process to install the base image, you will receive the following warning: “WARNING: DesktopAppConverter : warning 'W_ENABLING_FEATURE': Required feature 'Containers' is not enabled. Attempting to enable it now (this will require a restart)”. Respond with yes to restart the computer and the component will be installed automatically.
    2. You can manually install this feature (use one of the two options, depending on the version of your OS): 
      • Right-click on the Start button, choose Apps and Features, from the right Programs and features and, in the left panel, the option Turn Windows features on or off. Here tick the “Container” component.
      • Right-click on the Start button, choose Programs and features and, in the left panel, the option Turn Windows features on or off. Here tick the “Container” component.
    1. In an elevated PowerShell session, with Administrator rights, please use the following command:
PS C:\Windows\system32> Enable-WindowsOptionalFeature -Online
-FeatureName containers –All
    1. The worst scenario is when you will receive the following error: “DesktopAppConverter : error 'E_FEATURE_NOT_AVAILABLE': Required Windows Feature 'Containers' is not available on your system”. This error means your system does not have the Container feature!!! To have the Container feature as a component of the Windows OS you need to run the Professional or Enterprise version of Windows 10. The previous message has warned you that this component is not available because your computer it runs an operating system that does not support it. So, upgrade or downgrade your OS in order to match the requirements: Windows 10 Professional or Enterprise versions.
  1. To perform the conversion process, you will need also the Windows 10 SDK installed on your system. Download the Windows 10 SDK from here https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk and install it. 

 Building the AppX


    Right now, you have all components installed and set. You are ready now to create your first application AppX file.  
     I am going to present two ways to build an AppX file. Each approach tracks a different goal: (1) to submit your AppX to the Windows Store and (2) to test your app locally on your PC.

 

So, first, let us build an Appx for Windows Store submission:

  1. In the first step, put the file with the extension MSI (SensorTag_BLE.msi in my case) into the folder:
    d:\Temp\InstallerWork\Installer\

    In order to have an error-free conversion, it is very important that your installer to be capable of silent/quiet installation - i.e. that it does not display one or more blocking user interface messages (e.g. to ask the user to press a couple of Next buttons). This requirement must be obeyed since in the conversion process you will not be able to interact with your application installer.
  1. Run Desktop App Converter (DAC) under administrative privileges.
  2. Inside the DAC environment run the command:
Some helpful information:
  • The Destination parameter is the place where the AppX package will be placed, not where the app is installed.
  • Note that the least-significant value of the Version (revision number) must be zero. For example, instead of the 9.2.6.86, you must use 9.2.6.0 as the version number. 
  • The parameters PackageName, Publisher and PackagePublisherDisplayName must be the same as the ones from your developer account: App ManagementApp Identity (see the information from the figure presented below).
  • MakeAppx has the significance that, other than generating the folder that will contain all the files that need to be packaged, you want also to generate the AppX package. In our case, this parameter can be excluded – anyway, we will build the AppX manually.
  • If the installer package (MSI file) ask the user to press a couple of Next buttons, it is possible that the installer still offers a silent installation mode, but it requires to be launched with a special parameter (like Setup.exe /s).  If that is your case, please specify this information with an additional parameter provided to the Desktop App Converter called “InstallerArguments”. For example, the previous command would be completed with: 
-InstallerArguments "/s"  
  1. Check if between the files used to build the AppX package (in this case all placed in the folder: d:\Temp\InstallerWork\Output\82971DobreaDan.BLESensorTags\PackageFiles\) you have an “uninstall.exe” file. If yes, delete this file. Uninstall.exe requires administrative privileges and Microsoft does not allow this for a UWP application.
      The following steps are required only you deleted the Uninstall.exe files otherwise you already have the file 82971DobreaDan.BLESensorTags.appx required to be submitted to the Microsoft Store.
  1. Now delete the file: 82971DobreaDan.BLESensorTags.appx.
  2. Being in the folder d:\Temp\InstallerWork\Output\82971DobreaDan.BLESensorTags run the command (MakeAppx.exe - creates an application package from the individual files on the disk):
"c:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64\makeappx.exe"
pack /d d:\Temp\InstallerWork\Output\82971DobreaDan.BLESensorTags\PackageFiles
/l /p BLESensorTags.appx
  1. And as a result finally, you have the file: BLESensorTags.appx.

Second, we will build the package required in order to install your app locally on your PC:

  1.  Put the file with the extension MSI (SensorTag_BLE.msi file in my case) into the folder:
 d:\Temp\InstallerWork\Installer\
  1. Run Desktop App Converter (DAC) under administrative privileges.
  2. Inside the DAC, run the same command as it was presented previously (at the third step) but at the end add “-Sign”.  The Sign parameter allows to automatically generate a certificate needed to properly sign the AppX package. Without this digital signature, the AppX package cannot be installed on a PC, which will not trust the application without an associated certificate.
  3. Enable Sideloading: you can install an Appx or an AppxBundle software package only if sideloading is enabled on your Windows 10 device. So, follow the steps: SettingsUpdate & SecurityFor Developers. In this point, set either “Sideload apps” or “Developer mode”.
  1. Now, manually install an AppX package without using the Microsoft Store. Just:
    1. double-click on the file 82971DobreaDan.BLESensorTags.appx or
    2. run the following cmdlet within PowerShell:
PS C:\Windows\system32> Add-AppxPackage -Path
"d:\Temp\InstallerWork\Output\82971DobreaDan.BLESensorTags\82971DobreaDan.BLESensorTags.appx"
            and you will be prompted with a dialog similar with the following one: 

  1. Pressing the Install button and the following error will appear:

     The reason for this error is that an AppX package must be signed with a valid certificate in order to be installed and this certificate needs to be trusted by the computer. To solve this problem, you will need to add the certificate (generated automatically by the “Sign” parameter) in the Trusted Root Certification Authority of the computer.
  1. Double click on auto-generated.cer and choose Install certificate.
  2. On the new window, choose Local machine and then the option Place all certificates in the following store
  3. By pressing the Browse button, make sure to choose Trusted Root Certification Authorities and complete the process.
  4. Tray again the steps 4 and 5. Now, after pressing the Install button, you will see a progress bar showing the installation status.

 Other problems and solutions

 

Windows 10 update

     With a new Windows 10 update, your specific build (like 16299) will go to another superior build (e.g. 17134) But, each specific Windows build needs to have a matching base Windows image for the Desktop App Converter to work correctly. So, a new base Windows image must be installed. For this, follow the steps:
  1. Open Desktop App Converter (DAC) with Administrative rights.
  2. You need to clean up the old base Windows image, otherwise the tool won’t be able to install the new one. To do it, you perform the following command: 
PS C:\Windows\system32>  DesktopAppConverter -Cleanup "ExpandedImage" –Verbose
  1. Once the operation is completed, you are ready to install the new base Windows image. So, follow the step 3 from the Components installation sub-chapter.

WSReset

     After you install your application, several times (dozens or hundreds of installations) locally and from the store to test different scenarios, you may face different types of problems while using Windows Store such as:
  • You can't update or install apps from Windows Store,
  • Frequent Store apps crashing or freezing problems,
  • Windows Store apps won't open or give error messages,
  • Windows Store opens and suddenly closes etc.
     After I tested several solutions to fix them, I discovered the ultimate solution, which will fix all these apps related problems (in 70% of the cases): WSReset. WSRese is OS’s program that can be used to clear and reset Windows Store cache. So, do the steps are:
  1. Press WIN+R keys together to launch RUN dialog box and then type wsreset and press Enter.
  2. It will immediately start the cache resetting process which may take a few moments. After clearing the cache, it'll launch Windows Store.
     WSReset.exe file is present in C:\Windows\System32 folder. You can also directly launch it from there.     If you are worried about your personalized settings or installed apps, no problem! WSReset command does not change any application setting or remove any previously installed app. It just clears Windows Store cache.


-= 👍👍👍 =-

No comments:

Post a Comment