3

I have a windows console application on C# that I'm trying to compile natively, because I need it to run on machines that don't have .Net 4.0 . I used ngen.exe and grabbed the output (myproject.ni.exe) and the DLL's, but when I copy it to another machine and try to run the exe it says it's not a valid win32 application. am I missing something?

Thanks.

Shahab78
  • 277
  • 1
  • 11
  • 2
    Ngen must always be run on the target machine, copying native images is wrong. It is **not** a workaround for a missing .NET install and a native image is not an executable program. There used to be "linkers" in the early days of .NET, they could not compete with software that's installed everywhere and available for free. – Hans Passant May 12 '14 at 20:29
  • Thanks a lot Hans, seems like I had a misunderstanding on what Ngen does. – Shahab78 May 12 '14 at 20:36

1 Answers1

3

Yes, NGen does not produce executable/native DLL, it does produce pre-JIT-ed code to be used with .Net assembly.

There are other tools (i.e. see Compiling C# to Native?) that may create standalone executable out of .Net assemblies, but NGen is not one of them.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • `pre-JIT-ed code to be used with .Net assembly` what does this mean ? and how can i use the ngen output file with my original assembly ?? – mrid Mar 30 '18 at 05:08
  • @mrid NGet will essentially run the same JIT-compiler to produce executable code from IL that would happen if you run your code normally. The output is saved to file and .Net loader is able to use that pre-JIT-ed image (as long as it is in right place) instead of running JIT-compiler on first call to each method. MSDN article [ngen.exe](https://learn.microsoft.com/en-us/dotnet/framework/tools/ngen-exe-native-image-generator) may help with understanding of the tool. If you have more specific question it would be better to ask new one. – Alexei Levenkov Mar 30 '18 at 05:24