【.Net Framework 体积大?】不安装.net framework 也能运行!?原理补充-3

继续补充点吧。接上一篇,我们实现了.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

.NET Framework 3.5
 
 

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 runtime host. The runtime host loads the runtime into a process, creates application domains within the process, and loads and executes user code within those application domains.

 

exe 的执行入口,就是那个mscoree.dll 。

所以 一旦在注册表 +系统目录中注册了这个Dll 那么托管语言的程序就能被加载执行。

 

 

This documentation is archived and is not being maintained.

Runtime Hosts

.NET Framework 3.5
 

 

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

.NET Framework 3.5
 

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 Hosting Interfaces.

To load the runtime into a process, a host calls the CorBindToRuntimeEx Function function. The prototype for CorBindToRuntimeEx Function is located in Mscoree.h in the Include directory of the Windows Software Development Kit (SDK). The host uses CorBindToRuntimeEx Function 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去开启承载进程。然后展开一系列的动作。

 

好了,看到这里,也基本能看出个大概了。

有网友希望提供精简版的安装包,期望各位能自己动手去完成。

 
posted @ 2017-02-14 17:18  特洛伊-Micro  阅读(1107)  评论(0编辑  收藏  举报