如何在 powershell.exe 以外的 netfx 主机中使用 Appx 模块

Appx PowerShell 模块已重定向到 netstandard2.0,以确保它在继续支持 .netfx 的同时与 .netcore 未来保持一致。 此重定向的结果是一项中断性变更,这意味着 Appx PS 模块 cmdlet(在 netfx 运行时下运行时)在从 powershell.exe 以外的进程运行时不起作用。

有两种方法可以缓解此更改,以在 powershell.exe 以外的 netfx 主机中使用 Appx 模块。

选项 1:想要在 netfx 运行时环境中使用 Appx PS 模块 cmdlet 的每个进程(非powershell.exe)都需要将以下 4 个运行时程序集添加到该进程可访问的位置。 通常,这将通过将这四个运行时程序集放在进程的 *.exe 文件旁边来完成。

  • System.Memory.dll(4.0.1.0、netstd、v2.0)
  • System.Numerics.Vectors.dll(4.1.4.0、netstd、v2.0)
  • System.Runtime.CompilerServices.Unsafe.dll(4.0.4.0、netfx、v4.0)
  • System.Security.Principal.Windows.dll(4.1.1.0、netfx、v4.0)

这四个运行时程序集可以在它们各自的 NuGet 包(4.5.0 版本)中找到。

选项 2:将进程的运行时环境从 netfx 重定向到 netcore。