继续补充点吧。接上一篇,我们实现了.net framework的精简的步骤。
有网友评论了,那个核心的 mscoree.dll
从.net framework 2.0开始,微软开始了新的CLR承载模型。程序域模型。
参考文档:
https://msdn.microsoft.com/en-us/library/9x0wh2z3(v=vs.90).aspx
Hosting the Common Language Runtime
For applications that were written by using the .NET Framework, hosting the common language runtime is completely transparent. If you compile your managed code as an .exe assembly, the runtime is started automatically by mscoree.dll when the .exe is run. However, unmanaged applications can also benefit from hosting the common language runtime. The runtime provides a framework for extending applications such as Microsoft Internet Information Services and Microsoft SQL Server 2005.
Whether it is invoked automatically, as with managed .exe assemblies, or loaded by using the unmanaged hosting API, a .NET Framework application requires a piece of code called a . The runtime host loads the runtime into a process, creates within the process, and loads and executes user code within those application domains.
exe 的执行入口,就是那个mscoree.dll 。
所以 一旦在注册表 +系统目录中注册了这个Dll 那么托管语言的程序就能被加载执行。
Runtime Hosts
The common language runtime has been designed to support a variety of different types of applications, from Web server applications to applications with a traditional rich Windows user interface. Each type of application requires a runtime host to start it. The runtime host loads the runtime into a process, creates the application domains within the process, and loads user code into the application domains.
从这段文字就看出来,虚机程序的奥妙所在。所有的虚机程序,都由运行时承载。
Loading the Common Language Runtime into a Process
Before any managed code can be executed, the host must load and initialize the common language runtime. All hosts start with an unmanaged stub because the runtime is not yet running in the process. The .NET Framework provides a set of unmanaged APIs called the hosting APIs that the host can use to start the runtime. For more information, see .
To load the runtime into a process, a host calls the function. The prototype for is located in Mscoree.h in the Include directory of the Windows Software Development Kit (SDK). The host uses to control which version of the runtime to load and the behavior of basic functions such as garbage collection and assembly loading. A host can set the values listed in the following table.
上述文字来自MSDN :https://msdn.microsoft.com/en-us/library/01918c6x(v=vs.90).aspx
托段代码加载执行前,需要开辟一个指定的进程进行承载。如何去开启运行时承载进行?.net 提供了一系列的非托管接口API,由这些API去开启承载进程。然后展开一系列的动作。
好了,看到这里,也基本能看出个大概了。
有网友希望提供精简版的安装包,期望各位能自己动手去完成。