Reputation: 36050
I am asking this question primarly to learn. Let's say I want to send a very small console application (50 lines of code Also I am using the System.Text.RegularExpresion namespace.)
to a friend writen on c# on .net framework 4.0 . I will like to make the application portable therefore I just send him the output of the bin directory.
Why does he has to install the .net framework 4.0 client which it takes quite a while. Also it will be nice to include only the dll libraries that I plan on using in this case system.dll (that library contains system.text.regularexpressions namespace).
In other words why is it that I cannot include system.dll in my console application in order to make it portable and for it to work on a computer that does not have the .net framework installed.
Why is the installation of .net framework 4.0 so complex? What would happen if windows where to place all .net libraries on C:\Program Files\.net framework 4.0\
and then on the installation write a key to the registry of the path where that framework was installed so that programs are able to find the nessesary dlls.
Why are installations so complex on general?
I tried to decomplile system.dll with reflector then include that on my project and that did not worked
I guess my question should have been why .net framework 4.0 takes so long to instal? Why is it not posible to run the .net framework 4.0 if windows where to place the necessary dlls on program files and then write to the registry the path where those dlls are located. That process would have been much faster. Why not do it that way?
Thanks for the help I understand now how important is the CLR. I guess the only part that I am missing to understand is why installations take so long. I understand that there are thousands of dlls. Unziping those dlls to program files and writing 10000 keys on the registry should be much more quicker.
Upvotes: 2
Views: 46240
Reputation: 906
The C# programming language requires the .Net framework be installed on the target computer first, before running the target program. VB.NET and F# have the same requirement. The .net framework is a very large set of libraries, requiring more than just a couple of .DLL files, but also access to the system registry. There is a fairly deep level of integration, most of it through COM, but going deep into Win32 (at least for WinForms).
Now, Microsoft could have make C# compile directly to native code, but that is not what they decided to do. These programs require the framework to be installed, by design. As it is now, the .Net framework is required. This was a bigger deal in 2001 when C# and .Net was first introduced, because everybody had to install it! Today, Windows 7 (and Vista) come with it pre-installed, making it easier to the user. For server-side (web apps), it is also not that big of a deal, because it is not a matter of installing it on many client computers
One way of looking at it would be that each program would require all of the libraries, making it more difficult to maintain bug fixes, if every program had their own collection of .Net libraries they used. With having one installation of the framework on a computer, when a bug is found, Microsoft can patch the one version of the framework, rather then the multiple locations the file(s) could be if each program had their own set of library files.
As for portability, you can use Mono to run these same .Net (C#) binaries on Linux and Mac. Of course, on those other platforms, you will still need an installation of Mono to make it work.
Upvotes: 4
Reputation: 44366
Your question seems to boil down to "Why do I need to install the entire .NET Framework, instead of including just the required DLL's?"
The answer is that .NET Framework consists of more than just DLL's. The other major component of the framework is the CLR, which is in charge of executing and managing .NET code. The .NET Framework consists of many other smaller things (such as compilers) which are not necessary to run code, but nevertheless included with the framework.
The CLR is more important to .NET than the DLL's themselves. It is analogous to the CPU on a computer. Without it, nothing can be done, and the executable programs you have are just garbage data. The CLR takes care of JIT compiling your code to a native executable, memory management, etc. It is very similar in concept to the JVM for Java applications.
Even the DLL's are more complex than it would seem. Although you could in theory (disregarding the CLR for a minute) deploy just the dependency DLL's with your application, remember that all those DLL's (with the exception of mscorlib) have dependencies on more DLL's, and so on, including a vast number of dependencies for a simple application.
Upvotes: 9