Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net-core

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?

like image 611
Alexander Tauenis Avatar asked May 10 '20 11:05

Alexander Tauenis


People also ask

How is .NET Core compiled?

Compiling MSIL to Native Code At execution time, a just-in-time (JIT) compiler translates the MSIL into native code. During this compilation, code must pass a verification process that examines the MSIL and metadata to find out whether the code can be determined to be type safe.

How do I change a platform target from x86 to a CPU?

Select x86 in the Copy settings from drop-down list box. Click OK. In the Configuration Manager dialog, be sure the box in the Build column is checked for all projects in the solution. Click Close.

How is .NET Core made cross-platform?

NET Core is cross-platform. It runs on Windows, OS X and multiple distributions of Linux. It also supports different CPU architectures. We're adding more Linux distribution and CPU architecture support with the eventual goal of .

What is the difference between any CPU and x86?

Show activity on this post. "Any CPU" means that when the program is started, the . NET Framework will figure out, based on the OS bitness, whether to run your program in 32 bits or 64 bits. There is a difference between x86 and Any CPU: on a x64 system, your executable compiled for X86 will run as a 32-bit executable.


1 Answers

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.

like image 73
b.pell Avatar answered Oct 19 '22 09:10

b.pell