Friday, June 19, 2020

New GitHub Script: Automating the transformation of MSIX packages into MSIX app attach, ready for WVD!

Introduction

Last week I published an article on using MSIX app attach to deliver Google SketchUp to a GPU powered Desktop running in WVD. In that article I also touched on the steps you need to take to transform an MSIX package into an MSIX app attach (vhd) package. As explained in that article as well, the MSIX source can be a native MSIX package delivered by an ISV / application vendor or the output from the MSIX packaging tool. For both scenarios the steps of transforming an MSIX into MSIX app attach are the same. There is a great article on Microsoft Docs that described the manual steps needed. I decided to automate those steps into a single PowerShell script and share it on GitHub!
I’m sharing a PowerShell script on GitHub that automates the transformation of MSIX packages into MSIX app attach, ready to use within Windows Virtual Desktop or on any other Windows 10 Build 2004!
Important note since I get this question a lot: I’m using WVD as the destination environment for the MSIX app attach. However, WVD is not a requirement for MSIX app attach at all and neither is hosting the destination VM in Azure! MSIX app attach can be used on any Windows 10 2004 build (and up). When you are using Windows 10 Enterprise it can be hosted anywhere and can even be a physical device. When Windows 10 Enterprise Multi-Session is used, it has be hosted on Azure through WVD.

Variables you can specify

The PowerShell script takes the parameters as shown below. I used a Google Chrome MSIX package that was the end result of the MSIX packing tool as an example to provide you with some sample values.
First of all you provide the information (folder and file) where the source MSIX is located, in this case I’m using a local folder on my MSIX Transformation VM. Next you provide the maximum size of the MSIX app attach (dynamic vhd) disk. Make sure you have enough room to store the extracted MSIX package files. Then provide a label, this label will be set on the vhd disk to allow you to easily distinguish multiple attached disks later on. Next you can provide the name of the root folder on the disk. As explained in my previous article, a root folder is mandatory for MSIX to work. Then provide the location where msixmgr is installed, this tool is used to extract the MSIX into the root folder on the vhd disk we’ll be creating. Make sure you point to the location where msixmgr.exe, applyacls.dll et cetera reside. The container extension variable can be kept default.

Requirements that need to be in place

Do note that the machine that you run this script on needs to have access to the PowerShell Cmdlets that work with VHD files (Mount-VHD, Dismount-VHD et cetera) which are part of the hyper-v module. The script assumes that this module is and the msixmgr tool have been installed, it does not check for that requirement (yet).
Here is a list of the steps that the PowerShell script performs:
  • Create a new VHD file in the source location specified and configure it with the maximum disk size specified
  • Mount the created VHD
  • Initialize the created disk
  • Create a partition on the disk
  • Create the MSIX root folder on the Mounted Disk
  • Extract the specified MSIX package into the mounted disk (using msixmgr)
  • Grab and output the Volume ID and Package Name to allow for easy copying. These values are needed later for the MSIX app attach Staging & Registering steps.
  • Dismount the VHD

Transformation script in action!

Let’s see the script in action! Below is my starting point. I have several MSIX packages that have previously been transformed from msi/exe to MSIX using the MSIX packaging tool. I have the script in this folder as well and the hyper-v module as well as the msixmgr are installed.
For this example I want to transform the Google Chrome package into MSIX app attach, so I specify the following parameters.
In my case the entire transformation of Google Chrome MSIX towards MSIX app attach only took 32 seconds! Below is what the output looks like. The script also outputs the Volume ID and Package name which allows for easy copying because they are needed for the MSIX app attach Staging & Registering steps later.
Here is the end result, a Google Chrome MSIX app attach (.vhd) file ready to go!

Test drive the end result

It’s now time to test-drive the vhd file to see if we can attach it to a user session and actually use the application. As explained in my previous article, MSIX app attach consists of 4 different steps Staging, Registering, De-Registering, De-Staging and Microsoft provides sample scripts for these 4 steps. To reiterate, here is an explanation of the terminology again.
So, the next step is to place the created .VHD on a Share (File Server of Azure Files) that is accessible by the client (in my case a Windows 10 Enterprise Multi-Session via WVD Spring 2020 Update). In my case, I added it as a 3rd package in the MSIX app attach share.
Now we can test the first MSIX app attach step, Staging. My Transformation script outputs the VolumeGuid as well as the package name, paste those values in the Stage script and also enter the location of the vhd hosted on the app attach share, as well as the parent folder that was used. Running the scripts mounts the vhd and creates the junction point to have Windows “think” a MSIX was extracted in C:\Program Files\WindowsApps.
The staging step only takes a second to complete, and here is the result, a mounted disk
And a junction point towards the disk
Now that Staging is complete, we can Register the application for the end user. Again, simply update the package name variable and run the Register script.
And here is the end result! Google Chrome is not installed locally, but it is available in the start menu using MSIX app attach and is running in the user session!

Final notes and download!

We are of course running PowerShell CmdLets to Stage and Register MSIX app attach applications. Under production circumstances (when MSIX app attach comes out of public preview), you would run the staging part during the machine boot (e.g. via a Computer GPO) and the registering part during user login (e.g. via a User GPO setting). In the future it is Microsoft’s plan to further integrate MSIX app attach into the WVD Service. The diagram below shows the MSIX app attach proposed milestones.
And finally, here is a link to the full script on GitHub, and as always if you have suggestions for the script feel free to send in a pull request or reach out to me directly! https://github.com/fberson/wvd/blob/master/Create-MSIXAppAttachContainer.ps1
— Happy Transforming!

No comments:

Post a Comment