Introducing the new App Installer template in Visual Studio 2019
Published Jul 05 2019 07:02 AM 11.7K Views
Microsoft

n the lasts months we have learned, here in this blog, how App Installer can help you distribute MSIX packages and keep them automatically updated without using the Store. First, we have learned how to generate such a file with Visual Studio and the wizard to create MSIX packages starting from a UWP project or a Windows Application Packaging Project. Then, in another post we have learned how Windows 10 1903 has introduced some highly requested features, like the ability to declare an update as critical or to show a prompt to the user to notify him that an update is available.

Unfortunately, until a while ago, there wasn't the chance to combine both these features in an easy way. When you start the wizard to generate a MSIX package and you opt-in for sideloading with auto updates, you can only specify a few options, like the URL where the package will be published and the update frequency. What if I want to use one of the new features added in 1903, like adding the ShowPrompt attribute to trigger the update notification? Right now, the only solution is to manually edit the .appinstaller file generated by Visual Studio after the package creation process has been completed. This approach is hard to maintain, especially if you're planning to leverage an agile approach and setup a CI/CD pipeline to automatically build and deploy your applications. You would need to add to add a task in your pipeline which manipulates the .appinstaller file and manually add the required attributes.

Starting from Visual Studio 2019 16.1, instead, there's a better solution: the App Installer template. Thanks to this template, which can be added inside a UWP or Windows Application Packaging Project, you can define the look & feel of the App Installer file and set some of the information as parameters, which will be automatically replaced by the real values during the package generation.

Let's see an example.

Add an App Installer template

Let's assume that we have a Win32 application packaged with the Windows Application Packaging Project, as in the following image:

wapp.png

Right click on the Windows Application Packaging Project and choose Add → New item. Among the available templates, you will find a new one called App Installer.

 

template.png

Give it a name. The new file, with .appinstaller extension, will be included inside the project and it will look like this:

<?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" />
  </UpdateSettings>

</AppInstaller>

As you can see, all the information which are dynamic and which are dependent by the package configuration are included with a placeholder, wrapped inside graphs. All these values will be replaced with the ones from the manifest and from the project's configuration during the package creation wizard.

Which is the advantage of this approach? Let's say that we want to leverage the new feature to display a notification to the user when he opens the application and an update is available. We just need to add the ShowPrompt attribute to the OnLaunch entry, as in the following example:

<?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" />
  </UpdateSettings>

</AppInstaller>

From now on, when we're going to generate a new package, all the parameters will be replaced with the real value, but the new ShowPrompt attribute, being fixed, will stay as it is.

Let's generate a package to test this. Right click on the Windows Application Packaging Project, choose Store → Create app packages and then, in the first screen, choose Sideloading and leave the option Enable automatic updates turned on. In the next step, choose the package configuration as usual, then hit Next. Now you will notice something different. You will still be able to configure the URL where you're going to deploy the package (which will be used to replace the {AppInstallerUri} parameter in the App Installer template), but you won't be able to configure the update frequency anymore. Additionally, the screen will display a warning that an App Installer template has been detected. Since now the update policies are controlled by the App Installer template, you don't need to set them anymore during the wizard. Actually, this is a good thing because the wizard doesn't support the new features introduced in Windows 10 1903, so the template gives you more flexibility.

sideloading.png

That's it. Now generate the package and, at the end of the process, you will see that the App Installer file will have retained the custom update frequency, but all the other values will have been replaced with the real ones which belong to your app:

<?xml version="1.0" encoding="utf-8"?>
<AppInstaller
	Uri="https://db-msixtest.azurewebsites.net/ContosoExpenses.Package.appinstaller"
	Version="1.0.5.0" xmlns="http://schemas.microsoft.com/appx/appinstaller/2017/2">
	<MainBundle
		Name="ContosoExpenses"
		Version="1.0.5.0"
		Publisher="CN=Matteo Pagani, O=Matteo Pagani, L=Como, S=Como, C=IT"
		Uri="https://db-msixtest.azurewebsites.net/ContosoExpenses.Package_1.0.5.0_Test/ContosoExpenses.Package_1.0.5.0_x86.msixbundle" />
	<UpdateSettings>
		<OnLaunch
			HoursBetweenUpdateChecks="0"
			ShowPrompt="True" />
	</UpdateSettings>
</AppInstaller>

App Installer and Azure DevOps

If you have a CI/CD pipeline for your desktop application hosted on Azure DevOps, there's a good news! The latest image for the Windows hosted agent includes Visual Studio 2019 16.1, so you can leverage the App Installer template also in your pipeline. It's enough to use, as Windows image, the one called windows-2019, as described in the documentation. This way you'll be able to automatically deploy on a website the MSIX package and the custom App Installer file, without having to manually change it to support the new features added in Windows 10 1903.

Wrapping up

In this post have learned how, thanks to a new feature added in Visual Studio 2019 16.1, we can combine the best of both worlds when it comes to support the App Installer technology: the easiness of automatically generating an .appinstaller file as part of the package creation process and the flexibility of the new update features added in Windows 10 1903.

Happy packaging!

9 Comments
Brass Contributor

Wrap up, :)

Brass Contributor

that is great 

 

Iron Contributor
Will make the installation creation process simpler.
Iron Contributor

Hello Matteo,

 

I follow your tutorial step by step and I found that it do not work. Adding custom .appinstaller file to the package project do not take effect to the output file AppPackages\ContosoExpenses.Package.appinstaller file. I test it using latest Visual Studio (16.4.2). I dive deep into this issue and I found error in tutorial and maybe also in VS.
You wrote that we have to add App Installer template file. On screenshoot the name of file is Packaging1.appinstaller oand, you said that we can give it a name. Both are wrong. If we use default name Packaging1.appinstaller or our own name (e.g. ContosoExpenses.appinstaller) then Visual Studio ignore this file and will not use it as template. So we do not see the warning that an App Installer template has been detected and, of course, our modification of template will not take effect to the output AppPackages\ContosoExpenses.Package.appinstaller file.
The reason is that template file have to be named exactly Package.appinstaller. If name is different, then VS ignore it. I used my own file name and then spend some hours to find why it do not work. Renaming file to Package.appinstaller helps immediately.

Copper Contributor

@MarosK 

 

Yeah, ran into the same problem. Thanks :)

Copper Contributor

It is not as dynamically as you say, I'm afraid.

Tried to change the 

<MainBundle Uri="{MainPackageUri}"/>

to someting like 

<MainBundle Uri="https://installserver.com/{Version}/{Version}_x64.msixbundle"/>

but neither the string value nor the placeholders are respected. Is always overwritten with the value of  {MainPackageUri}

 

/M

 

 

Microsoft

Hello @Apskalle , I'm afraid that dynamic support isn't as dynamic as you need for your scenario. Placeholders are fixed, the "dynamic" part is the possibility to customize the various attributes to control the automatic update story.

If you have such a requirement, your best approach would be to have the MSIX generated as part of a CI/CD pipeline and, with a PowerShell script, make the required changes to the XML before the build starts.

Copper Contributor

Yeah, I figured, but it would be a reasonable entry in the features wish list.

When you see a template like this one you intuitively think that tweaking it like I did would work.

 

The appinstaller is a great tool - lets make it even better ;)

 

/M

 

  

 

Copper Contributor

@Matteo Pagani , 

If the website/Installer url (mentioned in *.appinstaller) which hosts the msix packages is secured and requires some kind of authentication, then how do we configure the PackageManager so that it can access the packages and check for updates. I could not find anything related this in the PackageManger object model nor in *.appinstaller schema file.

 

Version history
Last update:
‎Jul 05 2019 07:02 AM
Updated by: