How to build a Framework app that will run on ARM64 or x86

David Brooks 1 Reputation point
2024-09-25T02:03:54.6+00:00

I have noticed the "Prefer native ARM64" checkbox that has been added to the Visual Studio project properties page, and would like to thank you because I can now produce an "Any CPU" assembly that is truly multi-targeted: it will run native on an ARM64 device, and run as x64 on an Intel device. I'm building simple WPF and Windows Forms apps under Framework 4.8.

However, that new checkbox and the "Prefer 32-bit" checkbox are mutually exclusive. Why? I have apps that will never need a 64-bit address space, and use up less memory when running as x86 on an Intel box. In one sample, an app uses 39MB on an Intel box running as x86, >54MB on the same box running x64 (and 56MB running on an ARM64 device native). It's around 64MB as x86 running on the ARM64 device under emulation, which I guess reflects the overhead of the Prism emulator.

Although I realize that two different "Prefer" boxes would be confusing, would it be possible to build an Any CPU assembly that would run native ARM64 if available, or fall back to x86 otherwise?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,099 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 30,566 Reputation points Microsoft Vendor
    2024-09-25T13:31:44.1233333+00:00

    Hello @David Brooks

    Welcome to Microsoft Q&A forum.

    I don’t think it’s possible currently.

    "AnyCPU Prefer 32-bit" processes run a 32-bit process on an ARM Windows system, but "AnyCPU Prefer native ARM64" processes should run a 64-bit process on ARM64. You cannot set them both at the same time.

    I am not 100% sure if this is possible in the future, maybe there will be a new platform option. But as you know, even "Prefer native ARM64" option is a new feature(start from VS 2022 17.11).

    I suggest you submit a suggestion ticket here: Developer Community – Visual Studio.

    Kind Regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.