Where's the .NET native?
Asked Answered
P

2

10

I was excited about the idea to compile C# code to native machine code downloaded the .NET native and intalled it. But I can't configure my build to compile to neither x86 nor x64. In fact, no other than "any CPU" arch is available:

enter image description here

Here's the VS about:

enter image description here

Edit: When I came to install, I selected this features:

enter image description here

Putrescent answered 5/4, 2015 at 22:37 Comment(9)
AFAIK .NET native is only supported for Windows Store apps. Desktop is not a supported target.Foundling
can't you still use ngen.exe? msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.110).aspxOnward
@MichaelEdenfield: From page "Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer," what does "installs them into the native image cache on the local computer" exatly mean? I ran this on my C# executable and after checked it with IL SPY and it show MSIL code and not native. I don't understand it...Putrescent
ngen is used on the target machine; it compiles your IL to native code so that when the CLR goes to run it, it's already JIT'd. It's not exactly the same as .NET Native but it's similar, which I why I suggested you give it a look.Onward
@MichaelEdenfield: I think I get it. But that jit-ed executable can run in other machine than where it was generated?Putrescent
@Putrescent The .dll file that you run ngen on doesn't get modified. It gets stored in the Native Image Cache (NIC), you can find it here: #5658066 You can copy the .dll to another machine and run ngen there since the original .dll isn't modified. A typical way this is used is running ngen as one of the steps in an installer program.Dune
I was able to generate and found this at C:\Windows\assembly\NativeImages_v4.0.30319_32\myProgram\db1496cf0295bbe6a9242d86c0d8e091\myProgram.ni.exe but I can't run it directly, isn't? if I try, I get This app can't run on your PC error message` I suppose that if I run ngen in each *.exe and *.dll and give that generate image files to the user it willn't work, isn't?Putrescent
I opened another thread asking more about ngen but I'm going to delete it: https://mcmap.net/q/1163418/-how-does-ngen-worksPutrescent
I think I'm late, but it seems that it's just UWP only. No one knows. I don't even know if Microsoft knows.Backpack
P
15

That's because your application is a Windows Forms application. From the docs:

This developer preview currently enables building apps for Windows Store on ARM and x64 architectures (stay tuned for x86.) .NET Native will soon enable a consistent and converged experience across devices. Today's preview supports Windows Store applications. We will continue to evolve and improve native compilation for the range of .NET applications.

Pineda answered 5/4, 2015 at 22:45 Comment(1)
Is this the same after two years?Ballade
O
1

This c# to c transpiler may be a good option for non Windows store applications

https://csnative.codeplex.com/

Osprey answered 19/4, 2016 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.