透過套件支援架構以參數啟動應用程式Launch Apps with Parameters through Package Support Framework

封裝支援架構會使用檔案上的 config.js來設定應用程式的行為。The Package Support Framework uses a config.json file to configure the behavior of an application.

程式Proceedure

若要將應用程式執行設定為在應用程式啟動期間接收傳入的參數值,必須完成下列步驟。To configure the application execution to receive parameter values passed into it during application launch, the following steps must be completed.

  1. 下載套件支援架構Download the Package Support Framework
  2. 在) 上設定套件支援架構 ( # B0Configure the Package Support Framework (config.json)
  3. 將套件支援架構檔案插入應用程式封裝Inject the Package Support Framework files into the Application package
  4. 更新應用程式的資訊清單檔Update the application's manifest file
  5. 重新封裝應用程式Re-package the application

下載套件支援架構Download the Package Support Framework

您可以使用獨立的 Nuget 命令列工具或 Visual Studio 來抓取封裝支援架構。The Package Support Framework can be retrieved by using the standalone Nuget commandline tool or via Visual Studio.

Nuget comandline 工具:Nuget comandline tool:

從 nuget 網站安裝 Nuget 命令列工具: https://www.nuget.org/downloadsInstall the Nuget commandline tool from the nuget website: https://www.nuget.org/downloads. 安裝之後,請在系統管理 PowerShell 視窗中執行下列命令列。After installing, run the following commandline in an administrative PowerShell window.

nuget install Microsoft.PackageSupportFramework

Visual Studio:Visual Studio:

在 Visual Studio 中,以滑鼠右鍵按一下您的方案/專案節點,然後挑選其中一個 [管理 Nuget 封裝] 命令。In Visual Studio, right-click on your solution/project node and pick one of the Manage Nuget Packages commands. 搜尋 PackageSupportFramework.psf ,以在 nuget.org 上尋找套件。然後,安裝它。Search for Microsoft.PackageSupportFramework or PSF to find the package on nuget.org. Then, install it.

在檔案上建立 config.jsCreate the config.json file

若要指定啟動應用程式所需的引數,您必須修改指定應用程式可執行檔和參數之檔案上的 config.js。To specify the arguements required to launch the application, you must modify the config.json file specifying the application executable, and parameters. 在設定 config.js檔案之前,請先參閱下表以瞭解 JSON strucuture。Prior to configuring the config.json file, review the following table to understand the JSON strucuture.

Json 架構Json Schema

ArrayArray 索引鍵key Value
應用程式所需applications idid 在封裝資訊清單中使用應用程式元素的 ID 屬性值。Use the value of the ID attribute of the Application element in the package manifest.
應用程式所需applications 可執行檔executable 您要啟動之可執行檔的封裝相對路徑。The package-relative path to the executable that you want to start. 它是應用程式元素的可執行屬性值。It's the value of the Executable attribute of the Application element.
應用程式所需applications 引數arguments (可執行檔的選擇性) 命令列參數引數。(Optional) Command line parameter arguments for the executable.
應用程式所需applications workingDirectoryworkingDirectory (選擇性) 封裝相對路徑,用來做為啟動應用程式的工作目錄。(Optional) A package-relative path to use as the working directory of the application that starts. 如果您未設定此值,作業系統會使用 System32 目錄作為應用程式的工作目錄。If you don't set this value, the operating system uses the System32 directory as the application's working directory. 如果您以空字串的形式提供值,則會使用參考之可執行檔的目錄。If you supply a value in the form of an empty string, it will use the directory of the referenced executable.
應用程式所需applications monitormonitor (選擇性) 如果有的話,監視器會識別要在啟動主要應用程式之前啟動的次要程式。(Optional) If present, the monitor identifies a secondary program that is to be launched prior to starting the primary application.
處理程序processes 可執行檔executable 在大部分的情況下,這會是上述設定的可執行檔名稱,並移除路徑和副檔名。In most cases, this will be the name of the executable configured above with the path and file extension removed.
修復fixups dlldll 要載入之修復 msix/.appx 的封裝相對路徑。Package-relative path to the fixup, .msix/.appx to load.
修復fixups configconfig (選擇性的) 可控制修復 dll 的行為。(Optional) Controls how the fixup dll will behave. 此值的確切格式會因修復修復而異,因為每個修復可以視需要解讀此「blob」。The exact format of this value varies on a fixup-by-fixup basis as each fixup can interpret this "blob" as it wants.

應用程式、進程和修復金鑰都是陣列。The applications, processes, and fixups keys are arrays. 這表示您可以使用 config.json file 來指定多個應用程式、進程和修復 DLL。That means that you can use the config.json file to specify more than one application, process, and fixup DLL.

進程中的專案具有名為可執行檔的值,其值應形成為 RegEx 字串,以比對不含路徑或副檔名的可執行處理常式名稱。An entry in processes has a value named executable, the value for which should be formed as a RegEx string to match the name of an executable process without path or file extension. 啟動器會預期 RegEx 字串 Windows SDK std:: library RegEx ECMAList 語法。The launcher will expect Windows SDK std:: library RegEx ECMAList syntax for the RegEx string.

{
    "applications": [
      {
        "id": "PSFExampleID",
        "executable": "VFS\\ThisPCDesktopFolder\\IG-Bentley.exe",
        "workingDirectory": "",
      }
    ],
}

將套件支援架構檔案插入應用程式封裝Inject the Package Support Framework files to the Application package

建立封裝暫存資料夾Create the package staging folder

如果您已經有 msix (或 .appx) 檔案,您可以將其內容解壓縮至版面配置資料夾,以作為封裝的臨時區域。If you have a .msix (or .appx) file already, you can unpack its contents into a layout folder that will serve as the staging area for your package. 您可以從命令提示字元使用 MakeAppx 工具來完成此動作。You can do this from a command prompt using the MakeAppx tool.

MakeAppx 工具可在其預設位置找到:MakeAppx tool can be found in its default location:

OS 架構OS Architecture 目錄Directory
Windows 10 x86Windows 10 x86 C:\Program Files\Windows Kits\10\bin [ Version] \x86\makeappx.exeC:\Program Files\Windows Kits\10\bin[Version]\x86\makeappx.exe
Windows 10 x64Windows 10 x64 C:\Program Files (x86) \Windows Kits\10\bin [ Version] \x64\makeappx.exeC:\Program Files (x86)\Windows Kits\10\bin[Version]\x64\makeappx.exe
makeappx unpack /p PrimaryApp.msix /d PackageContents

上述 PowerShell 命令會將應用程式的內容匯出至本機目錄。The above PowerShell command will export the contents of the application into a local directory.

插入必要的檔案Inject required files

將必要的32位和64位封裝支援架構 DLL (s) 和可執行檔新增至套件目錄。Add the required 32-bit and 64-bit Package Support Framework DLL(s) and executable files to the package directory. 使用下表做為指引。Use the following table as a guide. 您也會想要視需要包含任何執行時間修正。You will also want to include any runtime fixes as required. 請造訪 套件支援架構執行時間修正檔 文章,以取得使用套件支援架構進行執行時間修正的指引。Visit Package Support Framework Runtime fixes Docs article for guidance on using the Package Support Framework for runtime fixes.

應用程式可執行檔是 x64Application executable is x64 應用程式可執行檔是 x86Application executable is x86
PSFLauncher64.exePSFLauncher64.exe PSFLauncher32.exePSFLauncher32.exe
PSFRuntime64.dllPSFRuntime64.dll PSFLauncher32.dllPSFLauncher32.dll
PSFRunDll64.exePSFRunDll64.exe PSFRunDll32.exePSFRunDll32.exe

上述這些上述的檔案,以及檔案 ** 上的config.js** 必須放在應用程式套件目錄的根目錄中。These above identified files, as well as the config.json file must be placed within the root of your application package directory.

更新應用程式的資訊清單Update the application's manifest

在文字編輯器中開啟應用程式資訊清單,然後將應用程式元素的可執行檔案屬性設定為 PSFLauncher 可執行檔的名稱。Open the applications manifest in a text editor, then set the Executable attribute of the application element to the name of the PSFLauncher executable file. 如果您知道目標應用程式的架構,請選取適當的版本,PSFLauncher [x64/x86] .exe。If you know the architecture of your target application, select the appropriate version, PSFLauncher[x64/x86].exe. 如果不明,PSFLauncher32.exe 可在所有情況下運作。If unknown, PSFLauncher32.exe will work in all cases.

<Package ...>
  ...
  <Applications>
    <Application Id="PSFSample"
                 Executable="PSFLauncher32.exe"
                 EntryPoint="Windows.FullTrustApplication">
      ...
    </Application>
  </Applications>
</Package>

重新封裝應用程式Re-package the application

使用 makeappx 工具重新封裝應用程式。Re-package the application using the makeappx tool. 請參閱下列範例,以瞭解如何使用 PowerShell 封裝和簽署應用程式:See the following example of how to package and sign the application using PowerShell:

makeappx pack /d PackageContents /p PSFSamplePackageFixup.msix
signtool sign /a/v/fd sha256 /f ExportedSigningCertificate.pfx PSFSamplePackageFixup.msix