MSIX Start Menu Shortcut Icons are Incorrect

You may attempt to package an MSIX and upon testing, realise that the MSIX Start Menu shortcut icons are incorrect.  That is, the shortcuts may contain duplicate icons or the shortcuts may be missing completely and have failed to capture!

The reason for this is typically because we have captured an application that installs multiple shortcuts pointing to the same executable, but with different arguments/parameters that perform different functions.  For example:

Shortcut 1 (runs main app): C:\Program Files\Alkane\App.exe

Shortcut 2 (runs app config): C:\Program Files\Alkane\App.exe -config

And even though they have different icons in the Start Menu at time of capture, the MSIX capture process interprets them as being “the same executable”, and either uses the same icon for each shortcut in the MSIX package or omits capturing the shortcut altogether!

MSIX Start Menu Shortcut Icons are Incorrect

There are a couple of ways to resolve the issue of MSIX icons being incorrect.  The first approach is slightly “hacky” should we say, but it works.  We will use the aforementioned executable path as an example for both:

Approach 1 – Fixing MSIX Shortcuts During Capture

Essentially what we do here is make a copy of the target executable during the capture process and trick the MSIX packager into thinking it’s a different executable, and hence it will generate the appropriate icons.  We then edit the package to point the shortcut back to the original executable, and delete the copy we made.

  1. Start capture.
  2. Install application.
  3. Make a copy of C:\Program Files\Alkane\App.exe and call it (for example) C:\Program Files\Alkane\AppConfig.exe
  4. Change the shortcut that points to C:\Program Files\Alkane\App.exe -config to point to C:\Program Files\Alkane\AppConfig.exe -config
  5. Stop the capture.
  6. In the Package Editor tab of the MSIX packager, under the Manifest File section click Open File. Replace all instances of AppConfig.exe in the AppxManifest with the original App.exe. Save and close the manifest file.
  7. Go to the Package Files tab, and delete AppConfig.exe.
  8. Save and close the package.

Approach 2 – Retrospectively Fixing MSIX Shortcuts Post Capture

If we were retrospectively fixing the icons without recapturing the application, we must do a few things:

  1. Create new icons!  There is a free application that can assist, given an initial PNG file.  Save the new icons into a staging directory called, for example, C:\Alkane\NewIcons.
  2. Extract the MSIX by renaming the extension from .MSIX to .ZIP and extracting.
  3. Copy the new icons from C:\Alkane\NewIcons to the Assets directory of the extracted package.
  4. Update the shortcut icon names in the AppxManifest.xml for the relevant application (typically within the <VisualElements> node).
  5. Regenerate the Resources.pri file (Windows SDK required).
  6. Recompile the MSIX (Windows SDK required).
  7. Sign the MSIX (Windows SDK required).

Luckily, our free MSIX packaging tool can do all this in a few lines of code:

Install-Module AlkanePSF
Import-Module AlkanePSF -MinimumVersion 2.2.3 -Force

#configure AlkanePSF
Set-AlkanePSFConfiguration -MSIXInputFilePath "C:\Alkane\Test.msix" `
-MSIXOutputFilePath "C:\Alkane\Test-fixed.msix" `
-MSIXStagingFolderPath "C:\Alkane\Staged\" `
-MSIXCertificateFilePath "C:\Alkane\alkanecert.pfx" `
-MSIXCertificatePassword (ConvertTo-SecureString "AlkanePassword" -AsPlainText -Force) `
-MSIXArchitecture "64" `
-PSFType "TM" `
-TimManganZipUrl "https://github.com/TimMangan/MSIX-PackageSupportFramework/blob/develop/ZipRelease.zip-v2024-10-26.zip?raw=true"

#install prereqs (SDK, Tim Managan's PSF etc)
Install-AlkanePSFPrerequisite -ForceReinstall $false

#Stage and extract our MSIX package (in the same location as our input MSIX) so we can apply fixups
New-AlkanePSFStagedPackage

#copy new icons to assets folder
Copy-Item "C:\Alkane\NewIcons\*" "C:\Appsource\Staged\Assets"

#Regenerate resources
New-AlkanePSFResourcesPRI 

#replace icon name in AppxManifest
Add-AlkanePSFStringReplace -FindRegex "Assets\\OLDSHORTCUTNAME-" -ReplaceString "Assets\NEWSHORTCUTNAME-"

#Generate config and update manifest
Set-AlkanePSF -OpenConfigJson $false

#Compile and sign
New-AlkanePSFMSIX