共用方式為


如何產生命令行轉換的範本檔案

透過 MSIX 封裝工具,您可以透過兩種方式執行轉換:透過互動式 UI 或我們的命令行選項。 使用命令行時,您需要提供範本檔案,讓轉換能夠搭配您的特定設定和需求運作。 本文將協助您完成產生適合您之範本檔案的程式。

有兩種方式可以取得適合您的範本檔案:

  • 您可以使用 MSIX 封裝工具的 UI。 在工具的設定中,您可以指定您想要使用您所建立的每個 MSIX 套件產生轉換範本檔案。
  • 您可以採用 範例範本 ,並手動輸入每個轉換所需的組態。

從 MSIX 封裝工具產生轉換範本檔案

  1. 啟動 MSIX 封裝工具。
  2. 移至應用程式右上角的設定。
  3. 請確定已選取 [產生具有每個套件的命令行檔案] 選項。
  4. 對您需要的設定進行任何任何其他變更或修改(例如排除專案、結束代碼)。
  5. 儲存設定
  6. 使用安裝程式完成應用程式套件工作流程。
    • 如果您未選取安裝程式,您將無法產生轉換範本檔案。
    • 如果您使用 exe,您必須將無訊息旗標傳遞至安裝程式,以產生轉換範本檔案。
  7. 在轉換結束時,您將根據您選擇的安裝程式設定範本檔案,以及您現在可以重新用於未來轉換的目前設定。
    • 根據預設,轉換範本檔案會儲存在與 MSIX 套件相同的位置,但您可以在 [建立套件] 頁面上指定範本檔案的個別儲存位置。
    • 您仍然需要根據您想要在每個轉換結束時輸出的 MSIX 進行一些修改。

手動編輯轉換範本檔案

您可以手動編輯轉換範本檔案的範本參數,以產生適合您的範本檔案。 產生轉換範本檔案時,請注意您在範本檔案中新增的功能,因為有些人可能需要額外的架構參考才能運作。

轉換範本的參數參考

以下是可在轉換範本檔案中使用的完整參數清單。

ConversionSettings 說明
設定:: AllowTelemetry [選用] 針對工具的此引動過程啟用遙測記錄。
設定:: ApplyAllPrepareComputerFixes [選用] 套用所有建議的準備電腦修正程式。 使用其他屬性時,無法設定此項目。
設定:: GenerateCommandLineFile [選用] 將範本檔案輸入複製到 SaveLocation 目錄,以供日後使用。
設定:: AllowPromptForPassword [選用] 指示工具提示使用者輸入虛擬機器的密碼,以及針對未指定的必要簽署憑證輸入密碼。
設定:: EnforceMicrosoftStoreVersioningRequirements [選用] 指示工具強制執行從 Microsoft Store 和商務用 Microsoft Store 進行部署時所需的套件版本控制配置。
設定:: ServerPortNumber [選擇性]連接到遠端電腦時使用。 需要範本架構的 v2。
設定:: AddPackageIntegrity [選擇性]將套件完整性新增至每個產生的 MSIX。 需要範本架構的 v5。
ValidInstallerExitCodes [選擇性] 0 或更多 ValidInstallerExitCode 元素。 需要範本架構的 v2。
ValidInstallerExitCodes:: ValidInstallerExitCode [選擇性]指定工具可能不熟悉或需要重新啟動的任何安裝程序結束代碼。 需要範本架構的 v2。
ValidInstallerExitCodes:: ValidInstallerExitCode:: Reboot [選擇性]指定結束代碼是否應在轉換期間觸發重新啟動。 需要範本架構的 v3。
ExclusionItems [選用] 0 個或多個 FileExclusion 或 RegistryExclusion 元素。 所有 FileExclusion 元素必須出現在任何 RegistryExclusion 項目之前。
ExclusionItems::FileExclusion [選用] 要在封裝中排除的檔案。
ExclusionItems::FileExclusion::ExcludePath 要將檔案排除在封裝之外的檔案路徑。
ExclusionItems::RegistryExclusion [選用] 要在封裝中排除的登錄機碼。
ExclusionItems::RegistryExclusion:: ExcludePath 要將登錄機碼排除在封裝之外的登錄機碼路徑。
PrepareComputer::DisableDefragService [選用] 轉換應用程式時停用 Windows Defragmenter。 如果設定為 false,則會覆寫 ApplyAllPrepareComputerFixes。
PrepareComputer:: DisableWindowsSearchService [選用] 轉換應用程式時停用 Windows Search。 如果設定為 false,則會覆寫 ApplyAllPrepareComputerFixes。
PrepareComputer:: DisableSmsHostService [選用] 轉換應用程式時停用 SMS Host。 如果設定為 false,則會覆寫 ApplyAllPrepareComputerFixes。
PrepareComputer:: DisableWindowsUpdateService [選用] 轉換應用程式時停用 Windows Update。 如果設定為 false,則會覆寫 ApplyAllPrepareComputerFixes。
SaveLocation [選用] 用來指定工具儲存位置的元素。 如果未指定,套件將會儲存在 [桌面] 資料夾底下。
SaveLocation::PackagePath [選用] 儲存所產生 MSIX 套件的檔案或資料夾路徑。
SaveLocation::TemplatePath [選擇性]儲存所產生命令行範本之檔案或資料夾的路徑。
Installer::Path 應用程式安裝程式的路徑。
Installer::Arguments [選用] 要傳遞給安裝程式的引數。 工具會使用下列引數,以無訊息模式自動執行 MSI 安裝程式:"/qn /norestart INSTALLSTARTMENUSHORTCUTS=1 DISABLEADVTSHORTCUTS=1"。 注意:如果您使用 .exe 安裝程式,您必須傳遞自變數來強制安裝程式以無訊息方式執行。
Installer::InstallLocation [選擇性]如果已安裝,則為已安裝檔案之應用程式根資料夾的完整路徑(例如“C:\Program Files (x86)\MyAppInstalllocation”。
Installer::IsUnattendedInstallWithoutArgument [選擇性]如果應用程式允許在沒有無訊息自變數的情況下進行「自動安裝」,則應該使用這個屬性。 此屬性僅用於 .exe 安裝程式。
VirtualMachine [選用] 用來指定要在本機虛擬機器上執行轉換的元素。
VirtualMachine::Name 要用於轉換環境的虛擬機名稱。
VirtualMachine::Username 要用於轉換環境之虛擬機的用戶名稱。
RemoteMachine [選擇性]指定要在遠端電腦上執行轉換的專案。 需要範本架構的 v2。
RemoteMachine:: ComputerName 要用於轉換環境的遠端電腦名稱。 需要範本架構的 v2。
RemoteMachine:: Username 要用於轉換環境之遠端電腦的用戶名稱。 需要範本架構的 v2。
RemoteMachine:: EnableAutoLogon [選擇性]這會在遠端電腦上執行需要重新啟動的轉換時自動將您重新登入,讓您的轉換順暢地繼續。 需要範本架構的 V3。
PackageInformation::PackageName MSIX 套件的套件名稱。
PackageInformation::PackageDisplayName MSIX 套件的套件顯示名稱。
PackageInformation::PublisherName MSIX 套件的發行者。
PackageInformation::PublisherDisplayName MSIX 套件的發行者顯示名稱。
PackageInformation::Version MSIX 套件的版本號碼。
PackageInformation::P ackageDescription [選擇性]MSIX 套件的描述。 需要範本架構的 v4。
PackageInformation::MainPackageNameForModificationPackage [選用] 主套件名稱的套件識別名稱。 如果建立的修改套件與主 (父系) 應用程式有相依性,則會用到此項目。
SigningInformation [選擇性]指定 Device Guard 簽署資訊的元素。 需要範本架構的 v4。
SigningInformation::DeviceGuardSigning [選擇性]指定 Device Guard 簽署信息的專案。 需要範本架構的 v4。
DeviceGuardSigning:: TokenFile Device Guard 以 JSON 格式簽署所需的 Azure AD 存取令牌。 需要 v4 範本架構。
DeviceGuardSigning:: TimestampUrl [選擇性]提供使用 Device Guard 簽署時的時間戳,以確保您的應用程式會在憑證存留期之後安裝。 需要範本架構的 v4。
應用程式 [選用] 用來在 MSIX 套件中設定應用程式項目的 0 個或多個應用程式元素。
Application::Id MSIX 應用程式的應用程式識別碼。 此識別碼將用於已偵測到且符合指定 ExecutableName 的應用程式項目。 套件中可以有多個可執行檔的應用程式識別碼值。

此值會是套件中應用程式的唯一識別碼。 此值有時稱為「套件相關應用程式識別碼 (PRAID)」。 套件內的識別碼不得重複 (相同識別碼只能在相同套件中使用一次)。 不過,識別碼一定不是全域唯一。 系統上可能有另一個套件使用相同的識別碼。

此字串包含以英文句點分隔的英數欄位。 每個欄位的開頭必須為 ASCII 字母字元。 您無法將這些值當做域值使用:“CON”、“PRN”、“AUX”、 “NUL”、“COM1”、“COM2”、“COM3”、“COM4”、“COM5”、“COM6”、“COM7”、“COM7”、“COM8”、“COM9”、“LPT1”、“LPT2”、“LPT3”、“LPT4”、“LPT5”、“LPT6”、“LPT7”、“LPT8” 和 “LPT9”。
Application::DisplayName MSIX 套件的應用程式顯示名稱。 此顯示名稱將用於已偵測到且符合指定 ExecutableName 的應用程式項目
Application::ExecutableName MSIX 應用程式的可執行檔名稱,這將會新增至套件資訊清單中。 如果偵測不到具有此名稱的任何應用程式,將會忽略對應的應用程式項目。
Application::Description [選用] MSIX 應用程式的應用程式描述。 如果未使用,則會使用應用程式的 DisplayName。 此描述將用於已偵測到且符合指定 ExecutableName 的應用程式項目
功能 [選用] 用來將自訂功能新增至 MSIX 套件的 0 個或多個功能元素。 “runFullTrust” 是轉換期間預設新增的功能。
Capability::Name 新增至 MSIX 套件的功能。

範例轉換範本檔案

<MsixPackagingToolTemplate
    xmlns="http://schemas.microsoft.com/appx/msixpackagingtool/template/2018"
    xmlns:V2="http://schemas.microsoft.com/msix/msixpackagingtool/template/1904"
    xmlns:V3="http://schemas.microsoft.com/msix/msixpackagingtool/template/1907"
    xmlns:V4="http://schemas.microsoft.com/msix/msixpackagingtool/template/1910"
    xmlns:V5="http://schemas.microsoft.com/msix/msixpackagingtool/template/2001">
<!--Note: You only need to include xmlns:v2 - xmlns:v5 if you are using one of the features that use those schemas -->

    <Settings
        AllowTelemetry="true"
        ApplyAllPrepareComputerFixes="true"
        GenerateCommandLineFile="true"
        AllowPromptForPassword="false" 
	    EnforceMicrosoftStoreVersioningRequirements="false"
        v2:ServerPortNumber="1599"
        v5:AddPackageIntegrity="true">    

	<!--Note: Exclusion items are optional and if declared take precedence over the default tool exclusion items
        <ExclusionItems>
            <FileExclusion ExcludePath="[{CryptoKeys}]" />
            <FileExclusion ExcludePath="[{Common AppData}]\Microsoft\Crypto" />
            <FileExclusion ExcludePath="[{Common AppData}]\Microsoft\Search\Data" />
            <FileExclusion ExcludePath="[{Cookies}]" />
            <FileExclusion ExcludePath="[{History}]" />
            <FileExclusion ExcludePath="[{Cache}]" />
            <FileExclusion ExcludePath="[{Personal}]" />
            <FileExclusion ExcludePath="[{Profile}]\Local Settings" />
            <FileExclusion ExcludePath="[{Profile}]\NTUSER.DAT.LOG1" />
            <FileExclusion ExcludePath="[{Profile}]\ NTUSER.DAT.LOG2" />
            <FileExclusion ExcludePath="[{Recent}]" />
            <FileExclusion ExcludePath="[{Windows}]\debug" />
            <FileExclusion ExcludePath="[{Windows}]\Logs\CBS" />
            <FileExclusion ExcludePath="[{Windows}]\Temp" />
            <FileExclusion ExcludePath="[{Windows}]\WinSxS\ManifestCache" />
            <FileExclusion ExcludePath="[{Windows}]\WindowsUpdate.log" />
	    <FileExclusion ExcludePath="[{Windows}]\Installer" />
            <FileExclusion ExcludePath="[{AppVPackageDrive}]\$Recycle.Bin " />
            <FileExclusion ExcludePath="[{AppVPackageDrive}]\System Volume Information" />
	    <FileExclusion ExcludePath="[{AppVPackageDrive}]\Config.Msi" />
            <FileExclusion ExcludePath="[{AppData}]\Microsoft\AppV" />
            <FileExclusion ExcludePath="[{Common AppData}]\Microsoft\Microsoft Security Client" />
            <FileExclusion ExcludePath="[{Common AppData}]\Microsoft\Microsoft Antimalware" />
            <FileExclusion ExcludePath="[{Common AppData}]\Microsoft\Windows Defender" />
            <FileExclusion ExcludePath="[{ProgramFiles}]\Microsoft Security Client" />
            <FileExclusion ExcludePath="[{ProgramFiles}]\Windows Defender" />
	    <FileExclusion ExcludePath="[{ProgramFiles}]\WindowsApps" />
            <FileExclusion ExcludePath="[{Local AppData}]\Temp" />
	    <FileExclusion ExcludePath="[{Local AppData}]\Microsoft\Windows" />
	    <FileExclusion ExcludePath="[{Local AppData}]\Packages" />

            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Wow6432Node\Microsoft\Cryptography" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Microsoft\Cryptography" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Microsoft\Microsoft Antimalware" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Microsoft\Microsoft Antimalware Setup" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Microsoft\Microsoft Security Client" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Policies\Microsoft\Microsoft Antimalware" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" />
            <RegistryExclusion ExcludePath= "REGISTRY\USER\[{AppVCurrentUserSID}]\Software\Microsoft\Windows\CurrentVersion\Explorer\StreamMRU" />
            <RegistryExclusion ExcludePath= "REGISTRY\USER\[{AppVCurrentUserSID}]\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\StreamMRU" />
            <RegistryExclusion ExcludePath= "REGISTRY\USER\[{AppVCurrentUserSID}]\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams" />
            <RegistryExclusion ExcludePath= "REGISTRY\USER\[{AppVCurrentUserSID}]\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Streams" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Microsoft\AppV" />
            <RegistryExclusion ExcludePath= "REGISTRY\MACHINE\SOFTWARE\Wow6432Node\Microsoft\AppV" />
            <RegistryExclusion ExcludePath= "REGISTRY\USER\[{AppVCurrentUserSID}]\Software\Microsoft\AppV" />
            <RegistryExclusion ExcludePath= "REGISTRY\USER\[{AppVCurrentUserSID}]\Software\Wow6432Node\Microsoft\AppV" />
        </ExclusionItems>
	-->
    
    <!--Note: Specifying an installer exit code will allow you to automatically trigger a reboot during your conversion
      <v2:ValidInstallerExitCodes>
        <V2:ValidInstallerExitCode ExitCode="3010" V3:Reboot="true"/>
        <V2:ValidInstallerExitCode ExitCode="1641"/>
      </v2:ValidInstallerExitCodes>
    -->
	    
    </Settings>

    <!--Note: this section takes precedence over the Settings::ApplyAllPrepareComputerFixes attribute and is optional
    <PrepareComputer
        DisableDefragService="true"
        DisableWindowsSearchService="true"
        DisableSmsHostService="true"
        DisableWindowsUpdateService="true"/>
    -->

    <SaveLocation
        PackagePath="C:\users\user\Desktop\MyPackage.msix" 
        TemplatePath="C:\users\user\Desktop\MyTemplate.xml" />

    <Installer
        Path="C:\MyAppInstaller.msi"
        InstallLocation="C:\Program Files\MyAppInstallLocation" />
	
    <!--NOTE: This section specifies that the conversion will be run on a local Virtual Machine. This is optional if you want to change your conversion environment from the default local machine.
    <VirtualMachine Name="vmname" Username="vmusername"/>
    -->

    <!--NOTE: This section specifies that the conversion will be run on a remote machine.This is optional if you want to change your conversion environment from the default local machine.
    <v2:RemoteMachine ComputerName="vmname" Username="vmusername" v3:EnableAutoLogon="true"/>
    -->

    <PackageInformation
        PackageName="MyAppPackageName"
        PackageDisplayName="MyApp Display Name"
        PublisherName="CN=MyPublisher"
        PublisherDisplayName="MyPublisher Display Name"
        Version="1.1.0.0"
        MainPackageNameForModificationPackage="MainPackageIdentityName">

    <!--Note: This is optional, if you want to sign your package with Device Guard signing
        <v4:SigningInformation>
            <v4:DeviceGuardSigning
                Tokenfile="tokenfile.json"
                TimestampUrl="https://mytimestamp.com"/>
        </v4:SigningInformation>
    -->
        
	<!--NOTE: This ID will be used if the Application entry detected matches the specified ExecutableName
        <Applications>
            <Application
                Id="MyApp1"
                Description="MyApp"
                DisplayName="My App"
                ExecutableName="MyApp.exe"/>
        </Applications>
	-->

	<!--NOTE: This is optional as “runFullTrust” capability is added by default during conversion
        <Capabilities>
            <Capability Name="runFullTrust" />
        </Capabilities>
	-->
	    
    </PackageInformation>
</MsixPackagingToolTemplate>