Question

I would like to distribute my .NET programs without the .NET framework. Is it possible to compile a .NET program to machine code?

Was it helpful?

Solution

Yes, you can precompile using Ngen.exe, however this does not remove the CLR dependence.

You must still ship the IL assemblies as well, the only benefit of Ngen is that your application can start without invoking the JIT, so you get a real fast startup time.

According to CLR Via C#:

Also, assemblies precompiled using Ngen are usually slower than JIT'ed assemblies because the JIT compiler can optimize to the targets machine (32-bit? 64-bit? Special registers? etc), while NGEN will just produce a baseline compilation.

EDIT:

There is some debate on the above info from CLR Via C#, as some say that you are required to run Ngen on the target machine only as part of the install process.

OTHER TIPS

Remotesoft has one: Salamander .NET Linker

I don't have any experience with it though.

There are some third party tools that do this, e.g.

Another (expensive and proprietary, licenses start at $1599) product that can do this is Xenocode Postbuild. Haven't used it myself though, with it costing about the gross national product of a small African country and all...

Is it possible to compile .NET IL code to machine code?

Yes, but the .NET Framework does it for you at runtime (default) or at install time (ngen). Among other reasons, this IL -> machine code is done separately on each install machine so it can be optimized for that particular machine.

I would like to distribute my .NET programs without the .NET framework. Is it possible to compile a .NET program to machine code?

No, for all intents and purposes you cannot do this. The 3rd party workarounds may work in some scenarios, but by then I wouldn't really consider it "managed code" or ".NET" anymore.

Yes, you can now! Recently Microsoft announced .NET Native, a piece of technology that compiles your application with .NET Native runtime (they call it MRT) into one binary (actually one executable and one dynamic library).

See links: http://blogs.msdn.com/b/dotnet/archive/2014/04/02/announcing-net-native-preview.aspx http://blogs.msdn.com/b/dotnet/archive/2014/04/24/dotnetnative-performance.aspx

There is IL2CPU for the compilation part.

I don't think that it is possible. You can make a prejitted assembly but you still need the framework.

If you just concerned with the size of deploying the Framework, you might read up on this.

I think you should not: That's the task of the JIT compiler.

However, you could use ClickOnce or Windows Installer to deploy it so that the missing framework isn't such a big problem: you could tell the installer to download the Framework and install it.

Look at MONO project: mono command with --aot option. http://www.mono-project.com/AOT

I'd always thought it would be cool to compile c# to machine code directly without the CLR dependency though....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top