且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-10-21 16:21:10

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

完成上述步骤后,请右键单击您的WapProjTemplate1,在弹出窗口中选择发布并选择创建应用程序包...然后选择选择和配置包向导中为架构发布,如下所示:

更新:

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

I followed 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 reads: If you're packaging a desktop application, right click on the the Windows Application Packaging Project node.. So I did just that (as shown below). But at the end of the wizard, I got the error shown at the end below:

Remark: My WPF project, MyWPFProject is a .NET 5 project, and the Application Packaging Project project name is WapProjTemplate1. I'm using latest version 16.9.3 of VS2019

Question: Why the error, and how can we resolve it. As, the following figure shows, my both projects target the same platform.

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 Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets

Please try to modify your Configuration Manager as below:

After completing the above steps, please right click your WapProjTemplate1, choose Publish on the popup and select Create App Packages... Then select Release for Architecture on Select and configure packages wizard as below:

Update:

On a 86-bit Windows operating system: Executables and DLL that are compiled with the Any CPU execute on the 32-bit CLR. On a 64-bit Windows operating system: A DLL compiled with the Any CPU executes on the same CLR as the process into which it's loaded. Executables that are compiled with the Any CPU execute on the 64-bit CLR. The Target Platform of the program and the referenced DLL should be consistent at runtime. Generally speaking, we can set the Target Platform of the program to be consistent with the deployed operating system according to actual needs and the DLL is preferably Any CPU. The special deployment environment requires special consideration. Maybe because your project is compatible with "Any CPU" but you have a dependency on a project or DLL that is either x86 or x64. Because you have an x86 dependency, technically your project is therefore not compatible with "Any CPU".