Search code examples
wpfazurevisual-studio.net-5msix

How do I get the MSIX appinstaller to output the correct settings during each build/publish?


Question:

How do I get the MSIX appinstaller to output the correct settings during each build/publish?

Context:

This is a follow-up question to Why does the MSIX not automatically check for updates every time the application runs when sideloading is enabled?

I am running:

  • Windows 10 20H2, OS Build 19042.928
  • Visual Studio 2019 Community edition, version 16.9.4

The MSIX Windows Targeting settings are as follows:

  • Target version = Windows 10, version 2004
  • Min version = Windows 10, version 1809

The MSIX installer project creates an invalid appinstaller file, which prevents the application from automatically checking for updates each time it runs. I can manually change the file after each build/publish, but I don't think I should have to do this because it seems both self-defeating and wrong.

Generally speaking, I would almost ignore creating the appinstaller each time, but the file auto-increments the version number. So, it seems like I am currently stuck with some form of manual intervention with either changing both the schema version and UpdateSettings section or update the version in the paths. Could this potentially be related to running Visual Studio Community edition? Do I need to have Professional in order to get it to work?

Appinstaller that Visual Studio creates, which is wrong:

<?xml version="1.0" encoding="utf-8"?>
<AppInstaller
    Uri="https://<AppService>.azurewebsites.net/<AppName>.Setup.appinstaller"
    Version="<AppVersion>" xmlns="http://schemas.microsoft.com/appx/appinstaller/2017/2">
    <MainBundle
        Name="<SomeGuid>"
        Version="<AppVersion>"
        Publisher="CN=<CertificateName>"
        Uri="https://<AppService>.azurewebsites.net/<AppName>.Setup_<AppVersion>_Development_Test/<AppName>.Setup_<AppVersion>_x64_Development.msixbundle" />
    <UpdateSettings>
        <OnLaunch
            HoursBetweenUpdateChecks="0" />
    </UpdateSettings>
</AppInstaller>

Appinstaller that I need Visual Studio to create:

<?xml version="1.0" encoding="utf-8"?>
<AppInstaller
    Uri="https://<AppService>.azurewebsites.net/<AppName>.Setup.appinstaller"
    Version="<AppVersion>" xmlns="http://schemas.microsoft.com/appx/appinstaller/2018">
    <MainBundle
        Name="<SomeGuid>"
        Version="<AppVersion>"
        Publisher="<CertificateName>"
        Uri="https://<AppService>.azurewebsites.net/<AppName>.Setup_<AppVersion>_Development_Test/<AppName>.Setup_<AppVersion>_x64_Development.msixbundle" />
    <UpdateSettings>
        <OnLaunch
            HoursBetweenUpdateChecks="0"
            ShowPrompt="true"
            UpdateBlocksActivation="true" />
        <AutomaticBackgroundTask />
        <ForceUpdateFromAnyVersion>true</ForceUpdateFromAnyVersion>
    </UpdateSettings>
</AppInstaller>

Solution

  • We resolved the issue with the application not checking for automatic updates even though sideloading is enabled. We need to add an additional item to the MSIX project of type App Installer. This will create a default file name of Package.appinstaller*. This file provides the configuration settings for the appinstaller file, which are needed in order to control all available settings, including the UpdateSettings section.

    Some additional features that the appinstaller allows for is to block the user from running the application without updating. This was a concern with the ClickOnce publish profile because it gave the user the option to skip the update; we were unable to find a way to prevent this. The MSIX appinstaller, however, allows for control over this behavior.

    *​DO NOT RENAME THIS FILE BECAUSE THE BUILD/PUBLISH UTILITY WILL NOT PICK IT UP AND APPLY THE SETTINGS TO THE APPINSTALLER FILE. THIS APPEARS TO BE A BUG/STATIC-FILE-REFERENCE.

    Package.appinstaller

    <?xml version="1.0" encoding="utf-8"?>
    <AppInstaller Uri="{AppInstallerUri}"
                  Version="{Version}"
                  xmlns="http://schemas.microsoft.com/appx/appinstaller/2018">
    
      <MainBundle Name="{Name}"
                  Version="{Version}"
                  Publisher="{Publisher}"
                  Uri="{MainPackageUri}"/>
    
      <UpdateSettings>
        <OnLaunch
            HoursBetweenUpdateChecks="0"
            ShowPrompt="true"
            UpdateBlocksActivation="true" />
        <AutomaticBackgroundTask />
        <ForceUpdateFromAnyVersion>true</ForceUpdateFromAnyVersion>
      </UpdateSettings>
    
    </AppInstaller>
    

    References:

    Additional References: