If I want to run a .NET application in a machine where the .NET framework is not available; Is there any way to compile the application to native code?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
I have tested several of them and at this moment the only one that supports .NET 3.5 and also has a great virtualization stack is Xenocode Postbuild
With ngen you still need to have the .NET framework installed but using a tool as such all your managed code is compiled into native code so you can deploy it to machines without the framework presence.
RemoteSoft makes a tool that compiles a .NET application into a package that can be run without .NET installed. I don't have any experience with it:
RemoteSoft Salamander
You can! However you're restricted to .NET 1.1 (no generics for you): Mono Ahead-Of-Time compilation (AOT)
However, this means compiling is really native, so you'll no longer be able to deploy one single bytecode assembly, you'll need one per platform.
It was originally designed because there's no .NET or Mono for iPhone, so that's how they made MonoTouch.
I think it's not possible. You will need to distribute .NET FW as well. If you want to compile .NET app to native code, use NGen tool
As some of the other answers here have mentioned, you can use the .NET Native tool to compile your app to native machine code. Unlike those answers, however, I will explain how to do it.
Steps:
Install the dotnet CLI (command line interface) tool, which is part of the new .NET Core toolchain. We'll use this to compile our app; you can find a good article about it here.
Open up a shell prompt and
cd
to the directory of your app.Type this:
That's it! When you're done, your app will be compiled down to a single binary, like this:
It'll be a standalone executable; no PDBs, assemblies, or config files included (hooray!).
Alternatively, if you want an even faster program, you can run this:
That will optimize your program using the C++ code generator (as opposed to RyuJIT), so your app is even more optimized for AOT scenarios.
You can find more info on this at the dotnet CLI GitHub repo.