什么是.NET程序集?我在网上浏览了一下,我不明白这个定义。


当前回答

维基百科说:

In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .NET assemblies contain code in CIL, which is usually generated from a CLI language, and then compiled into machine language at runtime by the CLR just-in-time compiler. An assembly can consist of one or more files. Code files are called modules. An assembly can contain more than one code module and since it is possible to use different languages to create code modules it is technically possible to use several different languages to create an assembly. Visual Studio however does not support using different languages in one assembly.

如果你真的浏览过,澄清你不理解的地方会有帮助

其他回答

用更简单的术语来说:可以由. net运行时环境执行的(预编译的)代码块。. net程序由一个或多个程序集组成。

物理集合类,接口,枚举等,这是在IL代码。可以是。exe或。dll文件。exe是可执行文件,. dll可以在任何。net支持的语言中动态使用。

除了公认的答案,我还想给大家举个例子!

例如,我们都在使用

System.Console.WriteLine()

但是System.Console.WriteLine的代码在哪里? 哪个代码是实际将文本放到控制台上的?

如果你看一下Console类文档的第一页,你会在顶部附近看到以下内容: 这表明控制台类的代码位于名为mscorlib的程序集中。程序集可以包含多个文件,但在本例中,它只有一个文件,即动态链接库mscorlib.dll。

mscorlib.dll文件在。net中非常重要,它是。net中类库的主要DLL,它包含了所有基本的。net类和结构。

如果你懂C或c++,通常你需要一个#include指令在顶部引用一个头文件。包含文件为编译器提供函数原型。相反,c#编译器不需要头文件。在编译过程中,c#编译器直接访问mscorlib.dll文件,并从该文件中的元数据中获取有关其中定义的所有类和其他类型的信息。

c#编译器能够确定mscorlib.dll确实在名为System的命名空间中包含一个名为Console的类,该类具有一个名为WriteLine的方法,该方法接受一个字符串类型的参数。

c#编译器可以确定WriteLine调用是有效的,并且编译器在可执行文件中建立对mscorlib程序集的引用。

默认情况下,c#编译器将访问mscorlib.dll,但对于其他dll,你需要告诉编译器类所在的程序集。这些被称为引用。

我希望现在明白了!

Charles pitzold

维基百科说:

In the Microsoft .NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .NET assemblies contain code in CIL, which is usually generated from a CLI language, and then compiled into machine language at runtime by the CLR just-in-time compiler. An assembly can consist of one or more files. Code files are called modules. An assembly can contain more than one code module and since it is possible to use different languages to create code modules it is technically possible to use several different languages to create an assembly. Visual Studio however does not support using different languages in one assembly.

如果你真的浏览过,澄清你不理解的地方会有帮助

程序集是构成逻辑功能单元的类型和资源的集合。.NET Framework中的所有类型都必须存在于程序集中;公共语言运行库不支持程序集之外的类型。每次使用Visual Basic . net创建Microsoft Windows®应用程序、Windows服务、类库或其他应用程序时,您都在构建单个程序集。每个程序集都存储为.exe或.dll文件。

来源:https://msdn.microsoft.com/en-us/library/ms973231.aspx#assenamesp_topic4

对于像我这样有Java背景的人来说,希望下面的图表能够阐明概念

程序集就像jar文件(包含多个.class文件)。您的代码可以引用现有的程序集,或者您的代码本身可以作为程序集发布,以供其他代码引用和使用(您可以将其视为Java中的jar文件,可以添加到项目依赖项中)。

最后,程序集是可以在任何安装了CLR的操作系统上运行的编译代码。这就相当于说.class文件或捆绑的jar可以在任何安装了JVM的机器上运行。