views:

862

answers:

10

Hello all,

Is there any approach to convert an application developed in .NET into a native executable (sources are included)?

Installing the whole framework (up to .NET Framework 3.5 SP1) takes a lot of time - not always the computers are updated from the internet. Is it possible to call NGen in order to produce independent executables?

Thanks

+8  A: 

No, NGen'd code still needs the framework - it only pre-JITs the code in your own assemblies. It also requires the framework for the CLR itself.

I believe Mono has a static compiler which they're planning on using for the iPhone. I don't know whether that will work on Windows as well though.

There used to be a product called Thinstall which some people used for this. It's now called ThinApp - basically it's application virtualisation. It's commercial, but you may well be able to get hold of a trial version.

Personally I'd be somewhat concerned about any such product - when it comes to deployment, veering away from the mainstream way of doing things sounds like a recipe for lots of support calls. There's just an awful lot to go wrong. I'm not saying it doesn't work, just that I'd be wary.

Have you looked at the .NET 3.5 (SP1) Client Profile? That may help to reduce your installation requirements a little.

Jon Skeet
Thinstall was brought by VMware and is now called "ThinApp" - http://www.vmware.com/products/thinapp/
Simon P Stevens
Thanks Simon - will update.
Jon Skeet
+12  A: 

It's not available yet, but the Mono project team are working on an Ahead of Time compiler that will do what you are looking for. The intention is for Mono to work on the iPhone (like Unity) but it should work for all platforms.

Edit: It does support Mono x86, but I'm not sure if they have included the feature that packs in dependent classes yet (though from an interview I heard, it's planned)

Edit 2: Including dependencies is currently supported, thanks Dykam!

Richard Szalay
The aot does work for a time already. I don't get what you mean with dependent classes. If you mean including referenced dll's, that is surely supported, as the bcl has to be compiled into the resulting executable too. Note that reflection and related is not available.
Dykam
Thanks Dykam. It may have been that optimisation of that process (ie. only including necessary classes and/or methods) that was mentioned as not being ready.
Richard Szalay
FYI, I believe the interview I mentioned was part of this episode of Hanselminutes: http://www.hanselminutes.com/default.aspx?showID=186
Richard Szalay
+3  A: 

You can use NGen to make your application a native executable, but it will still be dependent upon the .Net framework.

MusiGenesis
Why was this downvoted? The information is correct.
Richard Szalay
I think we cannot call it "native executable" while "still being dependent" upon the .NET framework.
lmsasu
It is a native executable in that it contains native code, but it still has dependencies on external libraries.
Richard Szalay
Well, I suppose that the external libraries still require .NET Framework runtime installed? Or maybe the "native executable" term is not the most appropriate?
lmsasu
Native executable is the correct term for this according to Microsoft. It is native code rather than MSIL, but still depends on the runtime libraries.
Frozenskys
NGen'd assemblies are native code, but still rely on the runtime for garbage collection (and possibly other things).
Richard Szalay
I should have said "native image" instead of "native executable", but that's irrelevant to the question here. The asker wanted to know if he could create a .Net executable that wasn't dependent upon the .Net framework.
MusiGenesis
+2  A: 

NGen compiles the exes to native exes, so they do not need to be JIT compiled as they are run. They are still dependant on the framework though.

There are a few commercial companies that do provide products for compiling .net assemblies into standalone exes. Xenocode and vmware's Thinapp. Neither are cheap though.

Simon P Stevens
+1  A: 

Some Obfuscators do this, you would have to do it beforehand though (before you ship it to your users). An example is remotesoft's Salamander.

Colin
+1  A: 

You will only need to install the version of .NET that you are targeting e.g. .NET1.1 or .NET2.0

Edit: If you need to target the 3.5 version you will need to install both 2.0 and 3.5

ILMerge (Free) can combine several assemblies into one, but I don't think that it works with the core runtimes.

In short I think that if you want to run .NET programs you will need the .NET Framework installed.

Frozenskys
.NET 3.5 are libraries on top of the .NET 2.0 framework.
ZippyV
Yes, I think you are right 1.1 and 2.0 are separate but 3.5 added extra libraries to 2.0
Frozenskys
+4  A: 
ZippyV
+1  A: 

There is a commercial product that claims to do that here:

http://www.xenocode.com/Obfuscator/

"Deploy .NET applications securely, with no .NET Framework install"

No idea what the drawbacks to this would be though

Kevin Laity
The price? lol.
Camilo Martin
Probably! I didn't want to create a login just to find out what the price was, so it must be alot.
Kevin Laity
+1  A: 

ThinApp (formerly Thinstall) from vmware. Used to be very expensive, though.

http://www.vmware.com/products/thinapp/

radim
+1  A: 

The only product we founded to solve the problem in 2007 was Xenocode Postbuild. From that time we use this product successfully, we use also its pretty good virtualization features.

The only problem is that the version we purchased don't support the Windows 7 (where you don't need to install .net framework to run your program compiled with version < 4.0). So I wrote to Xenocode. They answered

In order to get support for Win 7 you should upgrade to the newest version of Postbuild (now called .NET Obfuscator). Win 7 is not a supported platform for Postbuild 2007.

Shurup