Alexander Tauenis
Alexander Tauenis

Reputation: 373

How to compile a .NET Core project to "Any CPU" architecture?

Previously .NET Framework was able to make combo 32/64-bit EXEs in "Any CPU" mode selected in Visual Studio toolbar. Such EXEs was automatically 32-bit on Win32 and native 64-bit on Win64.

New .NET Core 3.1 is using different build process, not only via the "Build" button in VS, instead a "dotnet publish" command in terminal is the new and major. However, only "win-x86" and "win-x64" architectures are working here. "win-AnyCPU" is not working. The VS 2019 toolbar does not showing anything except "AnyCPU", but the selection does not working and last used from CLI architecture is used in EXE files maked via "Build" button.

How to make AnyCPU EXEs in .NET CLI?

Upvotes: 10

Views: 5122

Answers (1)

b.pell
b.pell

Reputation: 4318

As far as I know, the concept of AnyCPU isn't supported in .NET Core (even if you see it available as a setting in Visual Studio). Basically, you need to publish for each runtime identifier you want to support (e.g. you'd need to make a publish for x86 and a publish for x64, or one for linux-x64, etc.).

Here is a list of the runtime identifiers:

https://learn.microsoft.com/en-us/dotnet/core/rid-catalog

In addition to the runtime identifiers above, if you happen to use UWP API's you might have to target something more specific like net6.0-windows10.0.18362.

Upvotes: 4

Related Questions