Forum Discussion

peterbone's avatar
peterbone
Copper Contributor
Mar 17, 2025

Preview Handler with MSIX Packaging Tool?

Can anyone point me to a full example of an MSIX manifest file with a working preview handler for a custom file extension?

I have developed a Windows exe and a dll preview handler for a custom file extension. I have a working Inno Setup installer that creates file associations for the file extension and assigns a preview handler so that the files can be previewed in Windows Explorer. I'm then using MSIX Packaging Tool to create an MSIX from the Inno exe installer. It mostly works and file associations are created correctly for the custom file extension. However, the preview handler doesn't work. Windows Explorer just shows 'Preview Unavailable' in the preview pane.

I have found this topic, but it seems unresolved. Was this issue ever solved? 
Preview Handler in MSIX | Microsoft Community Hub
From this I have found that entries may be missing from my manifest file for desktop2:DesktopPreviewHandler and com:SurrogateServer. However, I am new to MSIX and my efforts to add them in based on the documentation (link below) only results in an 'Unable to parse manifest' error from the MSIX Packaging Tool. The log file isn't much help showing only '[Error] System.Runtime.InteropServices.COMException'.

https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-desktop2-desktoppreviewhandler

Can anyone point me to a working example for a manifest file for a preview handler for a custom file extension, or a good tutorial?

Here's my manifest file (with specifics renamed).

<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10" xmlns:desktop2="http://schemas.microsoft.com/appx/manifest/desktop/windows10/2" xmlns:desktop7="http://schemas.microsoft.com/appx/manifest/desktop/windows10/7" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap uap2 uap3 uap10 desktop7 rescap">
  <!--Package created by MSIX Packaging Tool version: 1.2024.405.0-->
  <Identity Name="CompanyName.AppName" Publisher="---------------------------------------" Version="1.1.1.0" ProcessorArchitecture="x86" />
  <Properties>
    <DisplayName>App Name</DisplayName>
    <PublisherDisplayName>Publisher Name</PublisherDisplayName>
    <Description>App Name</Description>
    <Logo>Assets\StoreLogo.png</Logo>
    <uap10:PackageIntegrity>
      <uap10:Content Enforcement="on" />
    </uap10:PackageIntegrity>
  </Properties>
  <Resources>
    <Resource Language="en-us" />
  </Resources>
  <Dependencies>
    <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22000.1" />
    <PackageDependency Name="Microsoft.WindowsAppRuntime.1.4" MinVersion="4000.1010.1349.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
  </Dependencies>
  <Applications>
    <Application Id="EXENAME" Executable="VFS\ProgramFilesX86\App_Name\AppName.exe" EntryPoint="Windows.FullTrustApplication">
      <uap:VisualElements BackgroundColor="transparent" DisplayName="App_Name" Square150x150Logo="Assets\APPNAME-Square150x150Logo.png" Square44x44Logo="Assets\APPNAME-Square44x44Logo.png" Description="App Name">
        <uap:DefaultTile Wide310x150Logo="Assets\APPNAME-Wide310x150Logo.png" Square310x310Logo="Assets\APPNAME-Square310x310Logo.png" Square71x71Logo="Assets\APPNAME-Square71x71Logo.png" />
      </uap:VisualElements>
      <Extensions>
        <com:Extension Category="windows.comServer">
          <com:ComServer>
            <com:SurrogateServer>
              <com:Class AppId="64644512-C345-469F-B5FB-EB351E20129D" SystemSurrogate="PreviewHost" />
            </com:SurrogateServer>
          </com:ComServer>
        </com:Extension>
        <desktop7:Extension Category="windows.shortcut">
          <desktop7:Shortcut File="[{Common Programs}]\App_Name\App_Name.lnk" Icon="[{Package}]\VFS\ProgramFilesX86\App_Name\AppName.exe" />
        </desktop7:Extension>
        <uap3:Extension Category="windows.fileTypeAssociation">
          <uap3:FileTypeAssociation Name="ext">
            <uap:SupportedFileTypes>
              <uap:FileType>.ext</uap:FileType>
            </uap:SupportedFileTypes>
            <uap:Logo>Assets\ext.png</uap:Logo>
            <uap2:SupportedVerbs>
              <uap3:Verb Id="open" Parameters=""%1"">open</uap3:Verb>
            </uap2:SupportedVerbs>
            <desktop2:DesktopPreviewHandler Clsid="64644512-C345-469F-B5FB-EB351E20129D" desktop10:DisplayName="AppNameEXTPreviewHandler" />
          </uap3:FileTypeAssociation>
        </uap3:Extension>
      </Extensions>
    </Application>
  </Applications>
  <Capabilities>
    <rescap:Capability Name="runFullTrust" />
  </Capabilities>
</Package>

 

2 Replies

  • peterbone's avatar
    peterbone
    Copper Contributor

    I've made some progress in getting the MSIX Manifest file to not return errors and previews are now partially working. Here's the updated manifest file.

    <?xml version="1.0" encoding="utf-8"?>
    <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap2="http://schemas.microsoft.com/appx/manifest/uap/windows10/2" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10" xmlns:desktop2="http://schemas.microsoft.com/appx/manifest/desktop/windows10/2" xmlns:desktop7="http://schemas.microsoft.com/appx/manifest/desktop/windows10/7" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10" IgnorableNamespaces="uap uap2 uap3 uap10 desktop2 desktop7 rescap com">
      <!--Package created by MSIX Packaging Tool version: 1.2024.405.0-->
      <Identity Name="CompanyName.AppName" Publisher="---------------------------------------" Version="1.1.1.0" ProcessorArchitecture="x86" />
      <Properties>
        <DisplayName>App Name</DisplayName>
        <PublisherDisplayName>Publisher Name</PublisherDisplayName>
        <Description>App Name</Description>
        <Logo>Assets\StoreLogo.png</Logo>
        <uap10:PackageIntegrity>
          <uap10:Content Enforcement="on" />
        </uap10:PackageIntegrity>
      </Properties>
      <Resources>
        <Resource Language="en-us" />
      </Resources>
      <Dependencies>
        <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22000.1" />
        <PackageDependency Name="Microsoft.WindowsAppRuntime.1.4" MinVersion="4000.1010.1349.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
      </Dependencies>
      <Applications>
        <Application Id="EXENAME" Executable="VFS\ProgramFilesX86\App_Name\AppName.exe" EntryPoint="Windows.FullTrustApplication">
          <uap:VisualElements BackgroundColor="transparent" DisplayName="App_Name" Square150x150Logo="Assets\APPNAME-Square150x150Logo.png" Square44x44Logo="Assets\APPNAME-Square44x44Logo.png" Description="App Name">
            <uap:DefaultTile Wide310x150Logo="Assets\APPNAME-Wide310x150Logo.png" Square310x310Logo="Assets\APPNAME-Square310x310Logo.png" Square71x71Logo="Assets\APPNAME-Square71x71Logo.png" />
          </uap:VisualElements>
          <Extensions>
    	    <!-- SurrogateServer entry added for linking preview handler -->
            <com:Extension Category="windows.comServer">
              <com:ComServer>
                <com:SurrogateServer>
                  <com:Class Id="64644512-C345-469F-B5FB-EB351E20129D" Path="VFS\ProgramFilesX86\App_Name\ExtPreview.dll" ThreadingModel="STA" />
                </com:SurrogateServer>
              </com:ComServer>
            </com:Extension>
            <desktop7:Extension Category="windows.shortcut">
              <desktop7:Shortcut File="[{Common Programs}]\App_Name\App_Name.lnk" Icon="[{Package}]\VFS\ProgramFilesX86\App_Name\AppName.exe" />
            </desktop7:Extension>
            <uap3:Extension Category="windows.fileTypeAssociation">
              <uap3:FileTypeAssociation Name="ext">
                <uap:SupportedFileTypes>
                  <uap:FileType>.ext</uap:FileType>
                </uap:SupportedFileTypes>
                <uap:Logo>Assets\ext.png</uap:Logo>
                <uap2:SupportedVerbs>
                  <uap3:Verb Id="open" Parameters=""%1"">open</uap3:Verb>
                </uap2:SupportedVerbs>
    			<!-- DesktopPreviewHandler entry added for linking preview handler -->
                <desktop2:DesktopPreviewHandler Clsid="64644512-C345-469F-B5FB-EB351E20129D" />
              </uap3:FileTypeAssociation>
            </uap3:Extension>
          </Extensions>
        </Application>
      </Applications>
      <Capabilities>
        <rescap:Capability Name="runFullTrust" />
      </Capabilities>
    </Package>

    The preview now shows in Windows Explorer, but there are a couple of issues.

    - It doesn't correctly take into account screen scale. When Windows Explorer is on a screen with > 100% scale the preview is shown too large and doesn't fit the preview area. This doesn't happen with the same preview handler installed using my Inno Setup installer.

    - The preview doesn't show at all in File Explorer from within my app. It shows a blank white canvas. Perhaps this is related to the scale issue and it's being drawn entirely outside the preview canvas?

    If anyone has experienced similar issues then I'd appreciate any help.

    • peterbone's avatar
      peterbone
      Copper Contributor

      I'm still trying to resolve these issues with the preview handler. Firstly, regarding the issue of the preview not working at all within File Explorer within my application, I noticed something curious. When I run the installed application from the start menu the preview doesn't work within the app. However, if I run the application executable directly from the WindowsApps install location then the preview does work. How is the way the application is run different when run from the start menu? I see from Task Manager that the app is not being run with elevated permissions regardless of if it's started from the start menu or directly from the exe. All other information in the Task Manager Details window also shows that the app is being run the same way in both instances. I also see in Task Manager that the Preview handler task appears when running the exe directly, but not when running from the start menu (a dllhost.exe task appears and then quickly disappears).

      I'm also still stuck on the screen scale issue. My original Inno installer does not cause the same issue despite the application exe and preview handler dll being identical.

Resources