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

Jack
  • 14,916
  • 47
  • 136
  • 245
  • 1
    AFAIK .NET native is only supported for Windows Store apps. Desktop is not a supported target. – Mike Zboray Apr 05 '15 at 22:43
  • 1
    can't you still use ngen.exe? https://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.110).aspx – Michael Edenfield Apr 05 '15 at 23:34
  • @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... – Jack Apr 06 '15 at 00:15
  • 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. – Michael Edenfield Apr 06 '15 at 01:00
  • @MichaelEdenfield: I think I get it. But that jit-ed executable can run in other machine than where it was generated? – Jack Apr 06 '15 at 01:10
  • @Jack 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: http://stackoverflow.com/questions/5657566/where-can-i-find-location-of-generated-file-after-doing-ngen 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. – Robert Rouhani Apr 06 '15 at 01:16
  • 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? – Jack Apr 06 '15 at 01:20
  • I opened another thread asking more about ngen but I'm going to delete it: http://stackoverflow.com/questions/29464018/how-does-ngen-works – Jack Apr 06 '15 at 01:20
  • 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. – Renzo Coppola Dec 17 '16 at 08:21

2 Answers2

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.

André Pena
  • 48,518
  • 37
  • 172
  • 216
1

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

https://csnative.codeplex.com/

dss
  • 460
  • 5
  • 11