7 Building for ARM64
Adam Yoblick редактировал(а) эту страницу 2020-02-20 17:55:54 -06:00

Windows Forms does not officially support native ARM64 yet. Windows10 running on ARM64 includes x86 emulation, so x86 Windows Forms binaries will work on an ARM64 device. However, there have been requests for instructions on how to generate native ARM64 Windows Forms binaries, so here there are. 😄

We will be building an application called WinformsControlsTest, contained within in the repo.

  1. Clone the repo at https://github.com/dotnet/winforms (I only tested with the release/3.1 branch)
  2. Remove .\src\System.Windows.Forms\tests\IntegrationTests\WinFormsControlsClassicTests\WinFormsControlsClassicTests.csproj from WinForms.sln.

At this point, the instructions differ slightly depending on the architecture of the machine you are building on.

Building on an x64 machine

If you are building on an x64 machine, you can use the x64 .net core sdk:

  1. Run .\build once in order to download/install the sdk specified in the global.json

  2. Run .\.dotnet\dotnet build -r win-arm64

    • This will generate the winforms arm64 binaries. The folder we're interested in is at .\artifacts\bin\WinformsControlsTest\Debug\netcoreapp3.1\win-arm64
  3. Double click WinformsControlsTest.exe in the folder above. You should see a windows error that looks like this:

     This app can't run on your PC
     To find a version for your PC, check with the software publisher.
    
  4. This means the exe is really built for arm! Copy the entire win-arm64 folder to an arm64 machine and double click on the exe. It should start up a form with buttons on it which you can click on to test the app.

Building on an arm64 machine

If you are building on an arm64 machine, you must use the x86 .net core sdk:

  1. Install the x86 .net core SDK manually from https://dotnet.microsoft.com/download/dotnet-core/3.1.
    • This is needed because the build scripts try to install the x64 one, which is wrong.
    • You might also need to install the x86 sdk into the .dotnet folder, like this: .\eng\common\dotnet-install.cmd -runtime "dotnet" -version "your.version.number" -architecture x86
  2. Change the versions in global.json to match the version you installed.
    • You should be changing tools.dotnet and sdk.version
  3. Run .\.dotnet\x86\dotnet build -r win-arm64
    • This will generate the winforms arm64 binaries. The folder we're interested in is at .\artifacts\bin\WinformsControlsTest\Debug\netcoreapp3.1\win-arm64
  4. Double click WinformsControlsTest.exe in the folder above. It should start up a form with buttons on it which you can click on to test the app.

Gotchas

Note that the WinformsControlsTest is a self-contained app, meaning you don't need to install the .net core runtime for it to work. If you are developing a non-self-contained app, you will also need to install an appropriate runtime using something like this:

.\eng\common\dotnet-install.cmd -runtime "dotnet" -version "3.1.0-preview3.19551.4" -architecture arm64

Just replace version with the version of the runtime you want to install.