0
votes

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:

enter image description here

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.

enter image description here

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

1
I encountered the same error and had to change the platform to x86 to suppress it. It's just a workaround though.emoacht
@emoacht I changed the platform to x64 and set the two values shown below in the screenshot from user @HuiLiu-MFST, to make it work. I agree it's a workaround. I would like to know how to make it work for Any CPU.nam
Fully agree. Any CPU should work.emoacht

1 Answers

0
votes

Please try to modify your Configuration Manager as below:

enter image description here 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: enter image description here

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".