C# 为什么 .NET 框架需要这么长时间才能安装?为什么让它便携起来很复杂?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12361070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why the .NET framework takes so long to install? Why is it complex to make it portable?
提问by Tono Nam
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.
我问这个问题主要是为了学习。假设我想将一个非常小的控制台应用程序发送给(50 lines of code Also I am using the System.Text.RegularExpresion namespace.)在 .net framework 4.0 上使用 c# 编写的朋友。我想让应用程序可移植,因此我只需将 bin 目录的输出发送给他。
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).
为什么他必须安装 .net framework 4.0 客户端,这需要很长时间。此外,只包含我计划在这种情况下使用的 dll 库 system.dll (该库包含 system.text.regularexpressions 命名空间)会很好。
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.
换句话说,为什么我不能在我的控制台应用程序中包含 system.dll 以使其可移植并使其在未安装 .net 框架的计算机上工作。
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.
为什么.net framework 4.0的安装这么复杂?如果 Windows 将所有 .net 库放在放置所有 .net 库的位置C:\Program Files\.net framework 4.0\,然后在安装时将密钥写入安装该框架的路径的注册表,以便程序能够找到必要的 dll,会发生什么。
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
我试图用反射器反编译 system.dll 然后将它包含在我的项目中,但没有用
Edit
编辑
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?
我想我的问题应该是为什么 .net framework 4.0 需要这么长时间才能安装?为什么不能运行 .net framework 4.0 如果 windows 在哪里放置必要的 dll 到程序文件上,然后将这些 dll 所在的路径写入注册表。这个过程会快得多。为什么不这样做呢?
So in conclusion
所以总结
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.
感谢您的帮助,我现在明白了 CLR 的重要性。我想我唯一不明白的部分是为什么安装需要这么长时间。我知道有数千个 dll。将这些 dll 解压缩到程序文件并在注册表上写入 10000 个键应该会快得多。
采纳答案by Kendall Frey
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?"
您的问题似乎归结为“为什么我需要安装整个 .NET Framework,而不是只包含所需的 DLL?”
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.
答案是 .NET Framework 不仅仅包含 DLL。该框架的另一个主要组件是 CLR,它负责执行和管理 .NET 代码。.NET 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.
CLR 对 .NET 来说比 DLL 本身更重要。它类似于计算机上的 CPU。没有它,什么也做不了,你拥有的可执行程序只是垃圾数据。CLR 负责将代码 JIT 编译为本机可执行文件、内存管理等。它在概念上与 Java 应用程序的 JVM 非常相似。
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.
甚至 DLL 也比看起来更复杂。尽管理论上您可以(暂时忽略 CLR)仅在应用程序中部署依赖项 DLL,但请记住,所有这些 DLL(mscorlib 除外)都依赖于更多 DLL,依此类推,包括大量依赖项对于一个简单的应用程序。
回答by PaulPerry
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).
C# 编程语言要求在运行目标程序之前,首先在目标计算机上安装 .Net 框架。VB.NET 和 F# 有相同的要求。.net 框架是一组非常大的库,不仅需要几个 .DLL 文件,还需要访问系统注册表。有相当深的集成水平,大部分是通过 COM,但深入到 Win32(至少对于 WinForms)。
Now, Microsoft couldhave 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
现在,Microsoft可以让 C# 直接编译为本机代码,但这不是他们决定做的。根据设计,这些程序需要安装框架。就像现在一样,需要 .Net 框架。在 2001 年首次引入 C# 和 .Net 时,这是一个更大的交易,因为每个人都必须安装它!今天,Windows 7(和Vista)预装了它,使用户更容易使用。对于服务器端(Web 应用程序),这也没什么大不了的,因为这不是在许多客户端计算机上安装它的问题
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.
一种看待它的方法是每个程序都需要所有的库,如果每个程序都有自己使用的 .Net 库集合,那么维护错误修复就会变得更加困难。通过在计算机上安装一个框架,当发现错误时,Microsoft 可以修补框架的一个版本,而不是如果每个程序都有自己的一组库文件,文件可能位于的多个位置。
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.
至于可移植性,您可以使用 Mono 在 Linux 和 Mac 上运行这些相同的 .Net (C#) 二进制文件。当然,在那些其他平台上,您仍然需要安装 Mono 才能使其工作。

