Hello everyone, this is Ingmar Oosterhoff, a Customer Engineer at Microsoft. In an earlier post I described how to set up an environment for a bulk conversion of .msi and .exe installers. But what about App-V? In this blog I will explain how easy it is to batch convert your App-V 5 packages to MSIX.
The MSIX packaging tool natively converts a single App-V package to MSIX, removing the requirement to re-package them and a feature we will make use of.
Let us start by preparing the host machine. In this case, my laptop. Components needed are contained in the shopping list below.
The shopping list:
- MSIX Packaging tool
- Folder containing App-V packages.
- A Signing certificate.
- Signtool.exe
- Conversion script
- Xml template
The MSIX Packaging Tool is free and can be installed from the Microsoft Store, so that is an easy step.
For the folder containing App-V packages, I am going to use my App-V Content Share. However, any folder that contains App-V packages will suffice.
Please keep in mind that User- and/or DeploymentConfig files of the App-V packages will be ignored.
Signing Certificate
I will need to sign the newly created MSIX packages with a certificate, so on my laptop on my C: drive I have created a folder named MSIX. In this folder I have created a folder Signing, this folder contains the certificate, used to sign the packages, and signtool.exe, which is part of the Windows 10 SDK (Software Developer Kit). (Have a look at our earlier post on how to set that up) |
The Script and xml template
In the MSIX folder I created earlier on the C: drive, I have a folder BatchConversion from my last post, and created an additional PowerShell file named batch_convert_appv.ps1, and the template file MsixPackagingToolTemplate.xml |
batch_convert_appv.ps1
The script below was created together with my fellow Customer Engineer Ryan Cobb. This script iterates through the list of App-V packages and converts them to MSIX. All that is needed is to copy the script and xml template from below, modify the following parameters within the script.
|
The location containing the App-V packages |
|
Certificate Publisher information must match the signing certificate. Have a look at my earlier post on how to retrieve that |
|
The Certificate friendly name |
|
The path to the signing certificate |
|
The password to use with the certificate |
$AppvContentStore = "C:\repository\App-V\Packages"
$PublisherName = "CN=Contoso Software (FOR LAB USE ONLY), O=Contoso Corporation, C=US"
$PublisherDisplayName = "Contoso"
$counter = 1
$Certificate = "C:\MSIX\Signing\ContosoLab.pfx"
$CertificatePassword = "notreallythecertificatepassword"
# Creating a folder to store the template files used for the conversion
New-Item -Force -Type Directory ([System.IO.Path]::Combine($workingDirectory, "MPT_Templates"))
# Creating a folder to store the MSIX packages
New-Item -Force -Type Directory ([System.IO.Path]::Combine($workingDirectory, "MSIX"))
# get all the App-V packages from the ContentStore
get-childitem $AppvContentStore -recurse | Where-Object { $_.extension -eq ".appv" } | ForEach-Object {
$Installerpath = $_.FullName
$filename = $_.BaseName
write-host "starting the conversion of: " $Installerpath
# MSIX package name cannot contain spaces, dashes or dots, so replacing these
$packageStrippedName = $filename -replace '\s+', '' -replace '\.', '' -replace '-', '' -replace '_', ''
$job = "job" + $counter
# get the contents of the template XML
[String]$newXml = Get-Content -path $PSScriptRoot\MsixPackagingToolTemplate.xml | Out-String
# Replace the placeholders with the correct values
$newXml = $newXml.Replace("[Installer]", "$Installerpath")
$newXml = $newXml.Replace("[SaveLocation]", "$SaveLocation")
$newXml = $newXml.Replace("[PackageName]", "$packageStrippedName")
$newXml = $newXml.Replace("[PackageDisplayName]", "$filename")
$newXml = $newXml.Replace("[PublisherName]", "$PublisherName")
$newXml = $newXml.Replace("[PublisherDisplayName]", "$PublisherDisplayName")
# saving the newly created template
$newXml | out-File MPTtemplate\MsixPackagingToolTemplate_$job.xml -Encoding Ascii -Force
# Starting the conversion
MsixPackagingTool.exe create-package --template "$MPTtemplate\MsixPackagingToolTemplate_$job.xml"
MsixPackagingTool.exe cleanup
$counter = $counter + 1
}
# App-V packages converted to MSIX. Signing the new MSIX packages
Get-ChildItem $msixFolder | foreach-object {
$MSIXpackage = $_.FullName
C:\MSIX\Signing\signtool.exe sign /a /v /fd SHA256 /f $Certificate /p $CertificatePassword "$MSIXpackage"
MsixPackagingToolTemplate.xml
Below the contents of the xml template file
<MsixPackagingToolTemplate
xmlns="http://schemas.microsoft.com/appx/msixpackagingtool/template/2018"
xmlns:mptv2="http://schemas.microsoft.com/msix/msixpackagingtool/template/1904">
<Installer Path="[Installer]"/>
<SaveLocation PackagePath="[SaveLocation]" />
<PackageInformation
PackageName="[PackageName]"
PackageDisplayName="[PackageDisplayName]"
PublisherName="[PublisherName]"
PublisherDisplayName="[PublisherDisplayName]"
Version="1.0.0.0">
</PackageInformation>
</MsixPackagingToolTemplate>
Once all the changes have been made and the script saved Batch Conversion can begin.
Open a PowerShell window as an administrator and change location to the Batch Conversion folder where the script is stored.
Type .\batch_convert_appv.ps1 and press enter
The script will convert all the App-V packages to signed MSIX packages and store them in a subfolder named MSIX.
Happy converting! Let me know how it went!
Ingmar Oosterhoff, Ryan Cobb, and Matthias Herfurth
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.