[FIXED] Azure Virtual Desktop (AVD) - Packaging the SQL Server Management Studio (SSMS) to MSIX
Published Jun 01 2022 05:13 PM 3,649 Views
Microsoft

In this post I will demonstrate how to package the Win32 SQL Server Management Studio (SSMS) to MSIX, that will be consumed later on Azure Virtual Desktop through MSIX App Attach.

 

MSIX is a Windows app package format that provides a modern packaging experience to all Windows apps. The MSIX package format preserves the functionality of existing app packages and/or install files in addition to enabling new, modern packaging and deployment features to Win32, WPF, and Windows Forms apps.

 

MSIX reduces the complexity of managing applications and golden images in AVDs. Through AVD application groups, applications can be instantly available without the need to create new Golden images. When FSLogix FSLogix Profile Containers and MSIX App Attach are used together, the operating system remains clean and the data, profile, and applications are completely separate.

 

The MSIX Packaging Tool enables you to repackage your existing desktop applications to the MSIX format. It offers both an interactive UI and a command line for conversions and gives you the ability to convert an application without having the source code. We want to enable IT Pros to convert their existing assets to MSIX, to give them a better way to do packaging and app management.

 

msixpackagingtool.png

 

In case you can't install the MSIX Packaging Tool from Microsoft Store, you can download the offline version here.

 

Another great option is to use the free Hyper-V image Windows 10 MSIX packaging environment that provides a Windows 10 image with the MSIX Packaging Tool already installed.

 

hyper-v.png

 

 

Packaging the SSMS to MSIX

 

Open the MSIX Packaging Tool and click Application package to create a new package for the application:

 

 

mpt_01.png

 

 

The MSIX Packaging Tool will monitor the changes that will be made to the operating system. For this, it is possible to use a virtual machine to install the application or the physical machine itself.

 

The best scenario is to use a virtual machine so that the same process can be repeated if necessary. It is important that the machine, used to install the application, does not contain the previously installed applications and their components.

 

Choose the desired scenario and click the Next button. While running the tool on a virtual machine, I selected the first option:

 

mpt_02.png

 

In this step, the tool will check if the MSIX Packaging Tool driver is already installed and will also disable Windows Update to decrease the number of changes to the operating system. The driver is already installed in the version provided by Hyper-V.

 

mpt_03.png

 

 

If you got an error to install the tool driver, please refer to this post that describes how to manually download and install the driver up to version 1809. Starting with version 1903, you need to download the Windows 10 Features on Demand ISO and copy the Msix-PackagingTool-Driver-Package.cab.

After verifying that the driver is installed, click the Next button.

 

Provide the installer of your application. It is important to note that the installer is not required, as the tool monitors all changes made to the operating system. I will provide the SSMS-Setup-ENU.exe installer.

 

Select the certificate that will be used to sign the package. The certificate is only required in case you want to install the app outside of the Microsoft Store (sideloading). For more information about how to create a self-signed certificate, please check this doc.

 

mpt_04.png

 

The next step is to fill in information such as the package name, the description that will be displayed to the user during installation, the vendor's name (must be the same as the certificate), and the version number. Fill in the requested information and click the Next button:

 

 

mpt_05.png

 

The following screen will appear and from then on, the tool will monitor the changes made to the operating system.

 

mpt_06.png

 

The installation will start automatically because we provided the SSMS installer.

 

mpt_07.png

 

 

In this step, I am just changing the destination path to reduce the path size. This is totally optional.

 

mpt_08.png

 

 

Click on Install and wait for the installation.

 

mpt_09.png

 

After completing the setup:

 

mpt_10.png

 

At the end of the installation, click the Next button. On the next screen, you need to define which apps will be visible in the start menu. I am keeping the suggested ones:

 

mpt_11.png

 

Click the Next button to continue.

 

The next screen asks for confirmation if the environment monitoring is done. Click the Yes, move on to continue:

 

 

mpt_12.png

 

On the next screen, just click on the Next button, since the SSMS application doesn't implements any service:

 

mpt_13.png

 

 

Now it is necessary to inform where the package will be generated, as well as it is possible to edit the package before saving it. Click the Package Editor button to review the package structure.

 

If we just finish the packaging process here, we will get the following error after trying to access the database or by clicking on "New Query" the Microsoft SQL Server Management Studio 18 packaged version:

 

Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

 

Using PROCMON, I just figured out that the issue happens because the SSMS was not finding the MSCOREE.DLL inside the package:

 

Process: C:\Program Files\WindowsApps\SSMS_1.0.0.0_x64__kz5d2ck10dqg4\VFS\ProgramFilesX86\SSMS\Common7\IDE\Ssms.exe
Operation: CreateFile
Result: PATH NOT FOUND
Path: C:\Program Files\WindowsApps\SSMS_1.0.2.0_x86__kz5d2ck10dqg4\VFS\ProgramFilesX64\WindowsApps\SSMS_1.0.2.0_x86__kz5d2ck10dqg4\VFS\SystemX86\mscoree.dll

 

Click on the Package files menu, navigate to the SystemX86 folder, right click on it and select Add file...:

 

mpt_fix01.png

 

 

 

Add the file "C:\Windows\SysWOW64\mscoree.dll":

 

mpt_fix02.png

 

When finished, click the Create button and inform where the file should be generated:

 

 

mpt_18.png

 

 

The following message will be displayed informing you that the package has been generated.

 

mpt_19.png

 

 

If you just try to install and run the package, you will receive the following error:

 

Cannot find one or more components. Please reinstall the application

 

Unfortunately, it is not possible to fix this error via MSIX Packaging Tool. In this case, we need to unpack the MSIX and change the key permissions for the virtual registry.

 

We can unpack the MSIX file through the MSIX Packaging Tool (MPT), but I am using MSIXHero as we will need to package it again and the MPT doesn't offers this option.

 

On MSIX Hero, select Unpack MSIX to directory:

 

msixhero01.png

 

Select the MSIX package to be extracted and click on Unpack package:

 

msixhero_ssms_01.png

 

Follows the extracted files:

 

msixhero_ssms_02.png

 

The next step is fixing the access permissions of the user.dat file. Therefore, run regedit, click on HKEY_LOCAL_MACHINE, and select Load Hive in the File menu:

 

msixhero_ssms_03.png

 

 

 

Be sure to use LOAD HIVE and not IMPORT, otherwise you will replace your registry information and compromise your machine.

 

Name the hive with a name of your preference, like ssms-user:

 

msixhero_ssms_04.png

 

Expand the loaded hive ssms-user, navigate to SOFTWARE, right click on it and select Permissions:

 

msixhero_ssms_05.png

 

 

Grant full control permission for the user Everyone:

 

reg02.png

 

Now that we fixed the permissions, we need to unload the virtual registry file. Select the key that was loaded, in my case, ssms-user, click on File menu and select unload hive:

 

msixhero_ssms_06.png

 

 

Switch back to MSIX Hero and choose Pack directory to MSIX:

 

 

msixhero_ssms_07.png

 

 

Select the folder to be packaged, check the sign this package, provide the certificate to sign the package in the Signature tab and click on Pack folder to MSIX package:

 

msixhero_ssms_08.png

 

 

Now that all finished the MSIX packaging, the next step is preparing the MSIX for Azure Virtual Desktop App Attach.

 

Creation of a VHDX package for MSIX

 

MSIX packages must be in a VHD or VHDX format to work properly. This means that you need to create a VHD or VHDX package to begin with, and we'll create it via the MSIXMGR tool.

 

After packaging a Win32 application to MSIX, we need to expand the package to a virtual disk (VHDX), so it can be dynamically attached to the user session during logon. It is very similar to FSLogix, but instead of profiles we are attaching the user's apps.

 

Download the MSIXMGR tool and extract the archive to a folder of your choice. I am using C:\msix\avd\msixmgr\x64 folder:

 

Use the following PowerShell (run as admin) command to generate the VHDX through MSIXMGR. Please change the path of the MSIXMGR tool and the MSIX and VHDX locations:

 

 

 

# size of the vhdx file
$vhdSize = 2500

# folder that will created inside the vhdx (You can get this name from the manifest file or via Get-AppPackage *adobe*)
$appParentFolder = "SSMS"

# vhdx destination. Notice that I am using the appParentalFolder to set the name
$vhdFullPath = "C:\msix\avd\vhdx\$appParentFolder.vhdx"

#application package name that can be obtained in the appxmanifest.xml or Get-AppPackage *SSMS*  | select PackageFullName
$packageName = "SSMS_1.0.1.0_x64__kz5d2ck10dqg4"

# msix file
$msixPath = "C:\msix\avd\msix\ssms\SSMS_1.0.1.0_x64__kz5d2ck10dqg4.msix"

#Expand the MSIX to VHDX
cd "C:\msix\avd\msixmgr\x64\"

.\msixmgr.exe -Unpack -packagePath $msixPath `
-destination $vhdFullPath `
-applyacls -create -vhdsize $vhdSize -filetype "vhdx" -rootDirectory $appParentFolder

 

 

 

Follows the expected result:

 

 

 

Successfully created virtual disk
Stopping the Shell Hardware Detection service
Stopping dependent services if necessary.
Successfully initialized and partitioned the disk.
Formatting the disk.
Successfully formatted disk

Finished unpacking packages to: C:\msix\avd\vhdx\SSMS.vhdx

Starting the Shell Hardware Detection service
Successfully started the Shell Hardware Detection Service

 

 

 

 

 

Follows the app running as MSIX on Windows 11:

 

ssms_final.png

 

 

 

 

I hope you liked it.

 

15 Comments
Co-Authors
Version history
Last update:
‎Jul 13 2022 03:36 PM
Updated by: