汇编,DLL和EXE [英] Assembly, DLL and EXE

查看:80
本文介绍了汇编,DLL和EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我总是把Assembly,.exe和.dll文件弄混了.
所有这些背后的基本概念是什么?
有什么异同.

请任何人都可以帮助我.

Hi All

I always confuse with Assembly, .exe and .dll files.
What is the basic concepts behind all these.?
What is the differences and similarities.?

Please any one can help me.

推荐答案

除了马库斯(Marcus)的答案外,也请看看以下答案:http://www.codeproject.com/Answers/218803/what-is-the-差异文件和dll文件 [
In addition to Marcus''s answer, do have a look at these answers too: http://www.codeproject.com/Answers/218803/what-is-the-difference-between-exe-and-dll-files[^]


程序集是一个复杂的概念,是.NET的主要单元.程序集及其标识有许多不同方面.如果可能是一个非常大文章的主题.您可以在这里开始阅读: http://msdn.microsoft.com/zh-CN -us/library/hk5f40ct(v = VS.90).aspx [入口点方法.通常,此静态方法称为Main,但也可以是其他任何一种,并且可以在编译参数中进行更改.

操作系统(.NET Framework)只是简单地约定"应加载程序集,然后定位并运行入口点(由程序集文件显示).我们每个人都可以创建具有完全不同类型的程序集的替代主机应用程序,该应用程序具有完全不同类型的入口点(甚至是一组不同的入口点),并支持完全不同的接口.

我在过去的解决方案中讨论了这样的体系结构:
创建使用可重载插件的WPF应用程序... [ ^ ],
AppDomain拒绝加载程序集 [使用CodeDom生成代码 [创建使用可重载插件的WPF应用程序... [ ^ ],
动态加载用户控件 [
Assembly is a complex concept, a main unit of the .NET. There are many different aspects of the assemblies and their identities. If could be a subject of really big article. You can start reading here: http://msdn.microsoft.com/en-us/library/hk5f40ct(v=VS.90).aspx[^].

I will only explain relationships between assembly and executable module. An EXE or DLL file are kinds of assembly executable modules. First surprising fact it: in .NET, there is no conceptual difference between DLL and EXE files.

Usually people know that EXE file is used to start a process from OS (normally, the Shell, but any process can start any other process; one special case is Service Controller use to start any application working as a Windows Service). DLL''s are used as class libraries. When a DLL is used as a main assembly module (see below), it can be referenced by other assembly, a DLL or EXE. In this way, a running process have one or more assemblies loaded, directly or indirectly. A running code can also load assembly dynamically, using System.Reflection.Assembly.

Now, this picture is typical but not mandatory. First, any executable module can have any arbitrary "extension" (actually NTFS does not have extensions (DOS had them), so this is a legace concept now understood as a part on file name). Actually, EXE file is exactly same thing as a class library normally represented by DLLs. There is only one simple convention: one class in EXE is special: it provides the class with static entry point method. Normally, this static method is called Main, but it can be anything else and can be altered in a compilation parameter.

The OS (.NET Framework) simply "knows" by convention that an assembly should be loaded, entry point (manifested by assembly file) located and run. Any of us can create alternative host application running completely different type of assembly with completely different type of entry point (or even a set of different entry points) supporting completely different interface.

I discussed such architectures in my past solutions:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^],
Dynamically Load User Controls[^].

From the other hand, .NET assembly represented by EXE file with which can work as traditional application can also be used as a regular class library. Any other assembly can reference it as a regular DLL. This fact is not very well known.

Finally, I promised to explain about modules. Visual Studio supports only the simplified modular model: every assembly is represented by its only executable module, EXE or DLL file (or anything, just one executable file). The general model could be used if you make a custom build or just a bare C# compiler (I''m not sure about other compilers): every assembly can be composed of several different files called modules. Don''t mix modules with referenced assemblies: no one of the modules represent the whole assembly. A module cannot be referenced by other assembly, it can only be used to create a new assembly. The same module can participate in two (or more) different assemblies. The same code may work in different way in different assemblies. For example, different assemblies can have different security permission. This would make some method placed in the module working properly when run in one assembly and fail in another one. One and only one of the modules in each assembly is called main module. It carries assembly manifest defining main assembly properties and identity. Again, with Visual Studio, each assembly is composed of just one module, so all modules are main.

—SA


此处有一篇文章可能是一个很好的起点: ^ ]
There''s an article here that might be a good starting point: http://en.wikipedia.org/wiki/.NET_assembly[^]


这篇关于汇编,DLL和EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆