MSIX 批量转换脚本

MSIX 工具包中的批量转换脚本可用于自动将 Windows 应用转换为 MSIX 包格式。 entry.ps1 脚本中提供了应用列表及其详细信息。

准备转换用的计算机

在运行 MSIX 工具包的批量转换脚本之前,若要自动将应用程序转换为 MSIX 打包格式,必须将你使用的设备(虚拟或远程)配置为允许远程通信,并安装 MSIX 打包工具。

术语 说明
主机 这是用于执行批量转换脚本的设备。
虚拟机 这是 Hyper-V 中现有的设备,托管在主机上。
远程计算机 这是可通过网络访问的物理机或虚拟机。

主机

主机必须满足以下要求:

  • 必须安装 MSIX 打包工具
  • 如果使用虚拟机,必须安装 Hyper-V。
  • 如果使用远程计算机:
    • 设备存在于与远程计算机相同的域中:
      • 启用 PowerShell 远程处理
        # Enables PowerShell Remoting
        Enable-PSRemoting -force
        
    • 设备与远程计算机一样存在于工作组或备用域中:
      • 启用 PowerShell 远程处理
      • WinRM 受信任的主机必须包含远程计算机的设备名或 IP 地址
        # Enables PowerShell Remoting
        Enable-PSRemoting -force
        Set-Item WSMan:\localhost\Client\TrustedHosts -Value <RemoteMachineName>,[<RemoteMachineName>,...]
        

远程计算机

远程计算机必须满足以下要求:

  • 必须安装 MSIX 打包工具

  • 如果设备与主机处于同一域中:

    • 启用 PowerShell 远程处理
    • 需要启用 WinRM
    • 允许 ICMPv4 通过客户端防火墙
      # Enables PowerShell Remoting
      Enable-PSRemoting -force
      New-NetFirewallRule -DisplayName “ICMPv4” -Direction Inbound -Action Allow -Protocol icmpv4 -Enabled True
      
  • 如果设备与主机一样存在于工作组或备用域中:

    • 启用 PowerShell 远程处理
    • WinRM 受信任的主机必须包含主机的设备名或 IP 地址
    • 允许 ICMPv4 通过客户端防火墙
      # Enables PowerShell Remoting
      Enable-PSRemoting -force
      New-NetFirewallRule -DisplayName “ICMPv4” -Direction Inbound -Action Allow -Protocol icmpv4 -Enabled True
      Set-Item WSMan:\localhost\Client\TrustedHosts -Value <HostMachineName>
      
      

虚拟机

建议使用 Hyper-V 快速创建“MSIX 打包工具环境”图像,因为它已预配置为满足所有要求。 虚拟机必须托管在主机上,并在 Microsoft Hyper-V 中运行。

虚拟机必须满足以下要求:

语法

entry.ps1

说明

这是一组 PowerShell 脚本,可将应用程序批量打包为 MSIX 包格式。 这些脚本将连接到本地的虚拟机或远程计算机,用于打包每个应用程序。

打包为 MSIX 应用程序格式的应用将按照输入 entry.ps1 脚本中的顺序进行转换。 entry.ps1 脚本中列出的远程计算机用于将应用程序打包为 MSIX 格式,将会单独使用。 虚拟机可多次用于将不同的应用程序打包为 MSIX 应用程序格式。

在运行脚本之前,必须先将要转换的应用添加到脚本中的 conversionsParameters 变量。 可将多个应用添加到变量。 该脚本利用应用和远程/虚拟机创建格式化的 XML 文件,满足 MSIX 打包工具 (MsixPackagingTool.exe) 的要求。 创建 XML 文件后,run_job.ps1 脚本在新的 PowerShell 进程中执行,该进程在目标设备上执行 MsixPackagingTool.exe,以转换应用并将其放置在脚本执行文件夹中的 .\Out 文件夹中。

示例

PS C:\> entry.ps1

该示例执行 entry.ps1 脚本。 此脚本将 conversionsParameters 变量中指定的应用转换为 MSIX 包。 应用使用 virtualMachinesremoteMachines 变量中指示的虚拟机或远程计算机进行转换。

参数

virtualMachines

参数 virtualMachines 是一个数组,其中包含将应用打包为 MSIX 格式时,要连接到和访问的虚拟机名称和凭据。

  • 类型:数组
  • 必需:
$virtualMachines = @(
    @{
        Name = "MSIX Packaging Tool Environment";   # Name of the virtual machine as listed in the Hyper-V Management console
        Credential = $credential                    # Credentials used to connect/login to the virtual machine.
    }
)

指定的虚拟机用于将应用打包为 MSIX 格式。 将使用出现提示时输入的凭据连接该虚拟机(在执行脚本 entry.ps1 后直接出现提示)。 将应用程序打包为 MSIX 打包格式之前,脚本将创建 Hyper-V VM 的快照,然后在打包应用程序后还原到该快照。

remoteMachines

remoteMachines 参数是一个数组,其中包含将应用打包为 MSIX 格式时,要连接到和访问的远程计算机的名称和凭据。 指定的远程计算机将是用于打包单个应用程序的一次性设备。

必须可在网络上访问和发现远程计算机。

  • 类型:数组
  • 必需:
$remoteMachines = @(
    @{
        ComputerName = "Computer.Domain.com";   # The fully qualified name of the remote machine.
        Credential = $credential }              # Credentials used to connect/login to the remote machine.
)

指定的远程计算机用于将单个应用打包为 MSIX 格式。 此远程计算机将使用出现提示时输入的凭据进行连接(在执行脚本 entry.ps1 后直接出现提示)。

在执行 entry.ps1 脚本前,确保设备的完全限定的域名或面向外部的别名可以解析。

signingCertificate

signingCertificate 参数是一个包含与代码签名证书相关信息的数组,该证书将用于对打包的应用程序进行签名。 此证书的加密级别必须至少达到 SHA256。

  • 类型:数组
  • 必需:
$SigningCertificate = @{
    Password = "Password"; 
    Path = "C:\Temp\ContosoLab.pfx"
}

conversionsParameters

conversionsParameters 参数是一个包含要转换为 MSIX 格式的应用相关信息的数组。 将对数组中的每个应用进行单独分析,并通过远程计算机或虚拟机上的 MSIX 包转换运行。 应用将按照其在脚本中显示的顺序进行转换。 如果转换为 MSIX 格式失败,脚本将不会重新尝试在不同的远程计算机或虚拟机转换应用程序。

  • 类型:数组
  • 必需:是
$conversionsParameters = @(
    ## Use for MSI applications:
    @{
        InstallerPath = "C:\Path\To\YourInstaller.msi";    # Full path to the installation media (local or remote paths).
        PackageName = "YourApp";                           # Application Display Name - name visible in the start menu.
        PackageDisplayName = "Your App";                   # Application Name - Can not contain special characters.
        PublisherName = "CN=YourCompany";                  # Certificate Publisher information - must match signing certificate
        PublisherDisplayName = "YourCompany";              # Application Publisher name
        PackageVersion = "1.0.0.0"                         # MSIX Application version (must contain 4 octets).
    },
    ## Use for EXE or other applications:
    @{
        InstallerPath = "Path\To\YourInstaller.exe";       # Full path to the installation media (local or remote paths).
        PackageName = "YourApp";                           # Application Display Name - name visible in the start menu.
        PackageDisplayName = "Your App";                   # Application Name - Can not contain special characters.
        PublisherName = "CN=YourCompany";                  # Certificate Publisher information - must match signing certificate
        PublisherDisplayName = "YourCompany";              # Application Publisher name
        PackageVersion = "1.0.0.0";                        # MSIX Application version (must contain 4 octets).
        InstallerArguments = "/SilentInstallerArguement"   # Arguements required by the installer to provide a silent installation of the application.
    },
    ## Creating the Packaged app and Template file in a specific folder path:
    @{
        InstallerPath = "Path\To\YourInstaller.exe";       # Full path to the installation media (local or remote paths).
        PackageName = "YourApp";                           # Application Display Name - name visible in the start menu.
        PackageDisplayName = "Your App";                   # Application Name - Can not contain special characters.
        PublisherName = "CN=YourCompany";                  # Certificate Publisher information - must match signing certificate
        PublisherDisplayName = "YourCompany";              # Application Publisher name
        PackageVersion = "1.0.0.0";                        # MSIX Application version (must contain 4 octets).
        InstallerArguments = "/SilentInstallerArguement";  # Arguements required by the installer to provide a silent installation of the application.
        SavePackagePath = "Custom\folder\Path";            # Specifies a custom folder path where the MSIX app will be created.
        SaveTemplatePath = "Custom\folder\Path"            # Specifies a custom folder path where the MSIX Template XML will be created.
    }
)

变量 conversionsParameters 中提供的应用信息将用于生成包含全部所需应用程序详细信息的 XML 文件。 创建 XML 文件后,接下来脚本会将 XML 文件传递给要打包的 MSIX 打包工具 (MsixPackagingTool.exe)。

日志记录

该脚本将生成一个日志文件,其中概述了在整个脚本执行过程中发生的情况。 日志文件将提供关于将应用程序打包为 MSIX 打包格式的相关详细信息,以及与脚本进程相关的信息。 可以从任何文本实用工具中读取日志,但已配置为使用 Trace32 日志读取器进行读取。 脚本执行中的错误将用红色突出显示,警告显示为黄色。 有关 Trace 32 日志读取器的更多信息,请访问 CMTrace

日志文件在脚本的目录 .\logs\BulkConversion.log 中创建。