究竟什么是 C# 或 .NET 中的程序集?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1362242/
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
What exactly is an Assembly in C# or .NET?
提问by Roee Adler
Could you please explain what is an Assembly in C# or .NET?
你能解释一下什么是 C# 或 .NET 中的程序集吗?
- Where does it begin and where does it end?
- What important information should I know about Assemblies?
- 它从哪里开始,又从哪里结束?
- 关于程序集,我应该了解哪些重要信息?
采纳答案by marc_s
An assembly is the compiled output of your code, typically a DLL, but your EXE is also an assembly. It's the smallest unit of deployment for any .NET project.
程序集是代码的编译输出,通常是 DLL,但您的 EXE 也是程序集。它是任何 .NET 项目的最小部署单元。
The assembly typically contains .NET code in MSIL (Microsoft Intermediate language) that will be compiled to native code ("JITted" - compiled by the Just-In-Time compiler) the first time it is executed on a given machine. That compiled code will also be stored in the assembly and reused on subsequent calls.
该程序集通常包含 MSIL(Microsoft 中间语言)中的 .NET 代码,这些代码将在第一次在给定机器上执行时编译为本机代码(“JITted” - 由即时编译器编译)。编译后的代码也将存储在程序集中并在后续调用中重用。
The assembly can also contain resources like icons, bitmaps, string tables and so on. Furthermore, the assembly also contains metadata in the assembly manifest - information like version number, strong name, culture, referenced assemblies and so forth.
程序集还可以包含图标、位图、字符串表等资源。此外,程序集还在程序集清单中包含元数据 - 诸如版本号、强名称、区域性、引用的程序集等信息。
In 99% of your cases, one assembly equals a physical file on disk - the case of a multi-file assembly (one assembly, distributed across more than a single file) appears to be a rather odd-ball edge case which I've never encountered so far in my 5+ years of .NET development.
在 99% 的情况下,一个程序集等于磁盘上的物理文件 - 多文件程序集(一个程序集,分布在多个文件中)的情况似乎是一个相当奇怪的边缘情况,我已经在我 5 年多的 .NET 开发中从未遇到过。
In a multifile assembly there would still be only one assembly manifest in a DLL or EXE and the MSIL code in multiple netmodule files.
在多文件程序集中,DLL 或 EXE 中仍然只有一个程序集清单,多个网络模块文件中仍然只有 MSIL 代码。
回答by Roee Adler
In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security.
在 Microsoft .NET 框架中,程序集是部分编译的代码库,用于部署、版本控制和安全性。
回答by Raghav
http://www.codeguru.com/columns/csharp_learning/article.php/c5845
http://www.codeguru.com/columns/csharp_learning/article.php/c5845
An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated.
程序集是编译器在成功编译每个 .NET 应用程序后自动生成的文件。它可以是动态链接库或可执行文件。它仅为应用程序生成一次,并且在每次后续编译时都会更新程序集。
回答by Chris S
Here'sanother explanation of the make up of .NET Assemblies, a mini-quote:
The .NET framework consists of the concepts of modules, assemblies, which both store metadata and manifest information. An assembly can contain multiple modules. Visual C# only ever creates one module which is turned into an assembly by the C# compiler (csc.exe), but an assembly can link many .NET modules together via the assembly linker (al.exe) command-line tool. For example each of your source code .cs files could be compiled into a module and linked together to form an assembly - an assembly is just a collection of modules and resources. One of these modules, however; must contain manifest metadata (see below) information for the assembly to be understood by the CLR.
....
Having created a new .exe or .dll inside VS.NET you see your file appear inside your bin folder. Opening it in notepad will give out gibberish, or even inside a hexadecimal editor without knowing the structure of the file, you need a tool like ildasm.exe or CFF explorer to make meaning from it. The structure of the assembly is as follows:PE header
CLR header
CLR metadata
CLR
IL code
Native data
.NET 框架由模块和程序集的概念组成,它们都存储元数据和清单信息。一个程序集可以包含多个模块。Visual C# 只创建一个由 C# 编译器 (csc.exe) 转换为程序集的模块,但程序集可以通过程序集链接器 (al.exe) 命令行工具将许多 .NET 模块链接在一起。例如,您的每个源代码 .cs 文件都可以编译成一个模块并链接在一起形成一个程序集 - 程序集只是模块和资源的集合。然而,这些模块之一;必须包含 CLR 能够理解的程序集的清单元数据(见下文)信息。
....
在 VS.NET 中创建新的 .exe 或 .dll 后,您会看到您的文件出现在您的 bin 文件夹中。在记事本中打开它会出现乱码,或者甚至在不知道文件结构的情况下在十六进制编辑器中打开它,您需要像 ildasm.exe 或 CFF explorer 这样的工具来从中获取意义。组件的结构如下:PE 标头
CLR 标头
CLR 元数据
CLR
IL 代码 本
机数据
回答by gaurav patni
When a source code is compiled by the language compiler it Generate a Managed Assemblyand MSIL(MisroSoft Intermediate Language). That Assembly contains .dll or .exe file. An Assebmly can be of two types Private Assemblyand Shared Assembly, shared Assembly is stored in GAC(Global Assembly Cache)so that any application can refer to it while private assembly is stored in application folder which can be used by only one Application.
当源代码由语言编译器编译时,它会生成托管程序集和 MSIL(MisroSoft 中间语言)。该程序集包含.dll 或 .exe 文件。一个Assebmly 可以有Private Assembly和Shared Assembly两种类型,共享Assembly 存储在GAC(全局程序集缓存)中,以便任何应用程序都可以引用它,而私有程序集存储在只能由一个应用程序使用的应用程序文件夹中。
回答by Anup Shetty
An assembly is a DLL or an EXE which will be created when you publish it or compile your application.
程序集是在您发布或编译应用程序时将创建的 DLL 或 EXE。
回答by kirti kant pareek
After writing source code of your program(project) then a file is created which may be DLL or EXE depends on your project. It makes only once for a single project. It has two types 1:- single 2:- shared or multiprogram single assembly used only in a single program while shared can be used for multiprogram
编写程序(项目)的源代码后,将创建一个文件,该文件可能是 DLL 或 EXE,具体取决于您的项目。它只为一个项目制作一次。它有两种类型 1:- 单个 2:- 共享或多程序 单程序集仅用于单个程序,而共享可用于多程序
回答by Abhay.Patil
An Assembly is a collection of logical units. Logical units refer to the types and resources which are required to build an application and deploy them using the .Net framework. Basically, Assembly is a collection of Exe and DLLs. It is portable and executable.
程序集是逻辑单元的集合。逻辑单元是指使用 .Net 框架构建应用程序和部署它们所需的类型和资源。基本上,Assembly 是 Exe 和 DLL 的集合。它是可移植和可执行的。
回答by snr
The answer is in order for immediate-grasping.
答案是为了立即掌握。
Put simply, it is the compiled project involving your classes and additional files, if there are. That is, each project in a solution is assembly.
简而言之,它是涉及您的类和其他文件(如果有)的编译项目。也就是说,解决方案中的每个项目都是assembly。
Or more techinally,
或者从技术上讲,
An assemblyis where a type is stored in the flesystem. Assemblies are a mechanism for deploying code. For example, the
System.Data.dll
assembly contains types for managing data. To use types in other assemblies, they must be referenced. - Source
一个组件是其中类型被存储在flesystem。程序集是一种部署代码的机制。例如,
System.Data.dll
程序集包含用于管理数据的类型。要在其他程序集中使用类型,必须引用它们。-来源
How do we know it? If you glance at properties of a projectunder the solutionyou can see the following images.
我们怎么知道?如果您查看解决方案下的项目属性,您可以看到以下图像。
When you compile the project, it turns out to DLLor EXE.
编译项目时,结果是DLL或EXE。