当前工作目录 PSFCurrent working directory PSF

包支持框架使用文件 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 to the Application package
  4. 更新应用程序的清单Update the application's manifest
  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 applicaiton, 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 keykey Value
applicationsapplications idid 使用包清单中的应用程序元素的 ID 属性的值。Use the value of the ID attribute of the Application element in the package manifest.
applicationsapplications 可执行文件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.
applicationsapplications 参数arguments 可执行文件 (可选) 命令行参数参数。(Optional) Command line parameter arguments for the executable.
applicationsapplications 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.
applicationsapplications 监视monitor (可选) 如果存在,则监视器将标识在启动主应用程序之前要启动的辅助程序。(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 进行加载。(Optional) Package-relative path to the fixup, .msix/.appx to load.
修正fixups configconfig (可选) 控制修正 dl 的行为方式。(Optional) Controls how the fixup dl behaves. 此值的准确格式因修正链接而异,因为每个修正都可以根据需要解释此 "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.js来指定多个应用程序、进程和修复 DLL。That means that you can use the config.json file to specify more than one application, process, and fixup DLL.

进程中的条目具有一个名为 "可执行文件" 的值,它的值应形成为正则表达式字符串,以便与无路径或文件扩展名的可执行进程的名称相匹配。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": "PSFSample",
            "executable": "PSFSampleApp/PrimaryApp.exe",
            "workingDirectory": "PSFSampleApp/"
        }
    ],
    "processes": [
        {
            "executable": "PSFSample"
        }
    ]
}

在上面的示例中 config.js文件时,PrimaryApp.exe 会将工作目录重新定向到 PSFSampleApp 目录。In the above example config.json file, the PrimaryApp.exe will have the working directory re-directed to the PSFSampleApp Directory.

将包支持框架文件注入到应用程序包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.exe 工具从命令提示符执行此操作。You can do this from a command prompt using the MakeAppx tool.

可在默认位置找到 Makeappx.exe 工具:MakeAppx tool can be found in its default location:

OS 体系结构OS Architecture DirectoryDirectory
Windows 10 x86Windows 10 x86 C:\Program Files\Windows Kits\10\bin arch> [ 版本] \x86\makeappx.exeC:\Program Files\Windows Kits\10\bin[version]\x86\makeappx.exe
Windows 10 x64Windows 10 x64 C:\Program 文件 (x86) \Windows Kits\10\bin arch> [ 版本] \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位包支持框架 () 和可执行文件。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'll 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. 这些文件可在 bin 目录内已安装的包支持框架目录中找到。These files can be found within the installed Package Support Framework directory inside of the bin 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.exe 工具重新打包应用程序。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