Bundle .NET dlls to run application in .NET-less machine?
Asked Answered
S

4

9

AFAIK, ngen turns MSIL into native code (also reffered to as pre-JIT), however I never payed too much attention at it's startup performance impact. Ngen'd applications still require the .NET base class libraries (the runtime).

Since the base class libraries have everything our .NET assemblies need (correct?) would it be possible to ship the framework's DLLs with my ngen'd application so that it does not require the runtime to be installed? (e.g., the scenario for most Windows XP machines)

Oh, and please don't bother mentioning Remotesoft's Salamander Linker or Xenocode's Postbuild. They are not for my (and many's) current budget (and they seem to simply bundle the framework in a virtualized enviroinment, which means big download sizes and slow startup times I believe)

EDIT:
I know now, ngen doesn't do what I thought it did.
But is it possible to bundle the .NET files with an application, without using a VM?

Sketch answered 16/3, 2010 at 11:5 Comment(0)
J
2

Have a look at Microsoft .NET Native:

.NET Native compiles C# to native machine code that performs like C++. You will continue to benefit from the productivity and familiarity of the .NET Framework with the great performance of native code.

It will be integrated in Visual Studio 2014.

Jemma answered 4/9, 2014 at 4:52 Comment(5)
At first I though "ah, another guy sending me a link to ngen docs", and now... I'm giggling - that they finally thought of this! As they mention, code starting and running faster and requiring less memory, that's just awesome! I wonder how compatible this will be with already-written code, but even though I don't have time or motivation to try this out at the moment, you deserve the green tick because this is now an official feature.Sketch
@CamiloMartin thank you, I became so excited when I found out about this too. I expect it to be very robust since it's going to ship with VS 2014.Jemma
Another thing that got me excited is that C# will have the ?. operator. How cool is that?! I guess they finally stopped having new ideas for spending time developing "yet another brand new way to do parallel/async" and are now forced to work on features which don't have anything to do with multithreading, lol.Sketch
@CamiloMartin, wow I did not know about that! thanks for sharing. I wish there was a way to subscribe to the "Completed" tag for C#Jemma
Hey, anyone can tell me if this made it in visual studio 2015?Joejoeann
S
5

You cannot do this. Many essential components such as the garbage collector are part of the CLR (which is part of the framework runtime), so in order to successfully execute your application you need the framework installed.

Slurry answered 16/3, 2010 at 12:17 Comment(4)
I understand, and I would really give up on the idea of being able to bypass the whole .NET setup if products such as Xenocode didn't exist. Kinda stubborn of me I know =PSketch
@Camilo Martin, 90% of Windows PCs already have .NET installed and 65% have .NET 3.5 SP1 installed (hanselman.com/blog/…). So why bother?Slurry
Well I don't know where he got those numbers, since I believe less than 90% of worldwide users have .NET 2.0. In any case, I just want my software to work even without .NET (or say, without .NET 3.5 SP1) installed. Those stats could be from the logs of a small blog visited by tech-aware people. Not to mention that, in my experience, most corporate/commerce/industry PCs are not allowed to install software, and many of them run on legacy OSes =(Sketch
Besides, IE6 is minority already and web developers bother about it. That's the same bothering I have for .NET.Sketch
P
2

That's not how Ngen works. It only bypasses the JIT compilation step. The resulting .ni.dll file only contains machine code, not the metadata of the assembly. You need to keep the original assembly available for that. And the CLR and the .NET framework assemblies must be available on the target machine, requiring you to install .NET.

Pod answered 16/3, 2010 at 11:50 Comment(3)
I'm sorry then, I've never used ngen myself. But Xenocode seems to run by embedding a framework subset within a virtual filesystem, and I believe it's not a full virtual OS like XP mode on Win 7, so there may be a way to leave out the absurdly long .NET setup and some redundant assemblies (to my application) in such a project. Also, network connectivity or that bloated target-all-processors 200+ MB redist wouldn't be necessary.Sketch
You can target the .NET Client Framework, it is only 26 MB. Re-inventing a linker is only technically feasible. The high license fees they charge for them is commensurate with the effort and the burden of keeping it compatible with framework releases. If this is an obstacle then targeting .NET is probably the wrong approach.Pod
Thanks for your comment, since the Client Framework is a good idea, and it seems Microsoft does not care about how developers should deal with Legacy OSes + different versions of the framework =( If I had to bloat my software by 26 MB witout having the install-hell of the framework, it would be beautiful already =(Sketch
J
2

Have a look at Microsoft .NET Native:

.NET Native compiles C# to native machine code that performs like C++. You will continue to benefit from the productivity and familiarity of the .NET Framework with the great performance of native code.

It will be integrated in Visual Studio 2014.

Jemma answered 4/9, 2014 at 4:52 Comment(5)
At first I though "ah, another guy sending me a link to ngen docs", and now... I'm giggling - that they finally thought of this! As they mention, code starting and running faster and requiring less memory, that's just awesome! I wonder how compatible this will be with already-written code, but even though I don't have time or motivation to try this out at the moment, you deserve the green tick because this is now an official feature.Sketch
@CamiloMartin thank you, I became so excited when I found out about this too. I expect it to be very robust since it's going to ship with VS 2014.Jemma
Another thing that got me excited is that C# will have the ?. operator. How cool is that?! I guess they finally stopped having new ideas for spending time developing "yet another brand new way to do parallel/async" and are now forced to work on features which don't have anything to do with multithreading, lol.Sketch
@CamiloMartin, wow I did not know about that! thanks for sharing. I wish there was a way to subscribe to the "Completed" tag for C#Jemma
Hey, anyone can tell me if this made it in visual studio 2015?Joejoeann
W
1

See How to compile a .NET application to native code? - the consensus looks to be that it's not possible.

Wind answered 16/3, 2010 at 11:15 Comment(1)
Yes, I know it's not possible to turn a .NET assembly into native code (i.e., translate .NET to native), but what I want is to simply bundle the runtime DLLs that I actually use (since most of them are pretty light-weight, such as system.dll being little more than 1 MB) and run my application with them, with the nice possibility of running more than one application and/or more than one version without re-packaging the whole thing (what both Salamander/Postbuild do). My main concern is to shave off size from the framework and be able to run my code without the framework present in the machine.Sketch

© 2022 - 2024 — McMap. All rights reserved.