为 Visual Studio 中的 MSIX 打包设置桌面应用程序时出错

Error when setting up desktop application for MSIX packing in Visual Studio

我关注this tutorial from official Microsoft team to use the Windows Application Packaging Project project in Visual Studio to generate a package for my WPF desktop app. A Note here 阅读:If you're packaging a desktop application, right click on the the Windows Application Packaging Project node.。所以我就这样做了(如下所示)。但是在向导结束时,我得到了下面末尾显示的错误:

备注:我的WPF项目,MyWPFProject是一个.NET 5项目,Application Packaging Project项目名称是WapProjTemplate1。我使用的是 VS2019

的最新版本 16.9.3

问题: 为什么会报错,如何解决。如下图所示,我的两个项目都针对相同的平台。

Error: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\MyFolder\MyWPFProject\bin\x86\Debug\net5.0-windows\win-x86\MyWPFProject.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. WapProjTemplate1 C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets

请尝试如下修改您的配置管理器:

完成上述步骤后,请右键单击您的 WapProjTemplate1,在弹出窗口中选择 Publish,然后 select Create App Packages... 然后 select Release for Architecture on Select and配置 packages 向导如下:

更新:

在 86 位 Windows 操作系统上:使用 Any CPU 编译的可执行文件和 DLL 在 32 位 CLR 上执行。 在 64 位 Windows 操作系统上:使用 Any CPU 编译的 DLL 与加载它的进程在同一 CLR 上执行。使用 Any CPU 编译的可执行文件在 64 位 CLR 上执行。 程序的 Target Platform 和引用的 DLL 在运行时应该是一致的。一般来说,我们可以根据实际需要将程序的Target Platform设置为与部署的操作系统一致,DLL最好是AnyCPU。特殊的部署环境需要特殊考虑。 可能是因为您的项目与“Any CPU”兼容,但您依赖于 x86 或 x64 的项目或 DLL。因为您有 x86 依赖项,所以从技术上讲您的项目因此与“Any CPU”不兼容。