了解dll以及它们在Visual Studio中的工作方式

时间:2022-01-11 07:00:53

Does anyone have a good resource on dlls and how they are used / generated in Visual Studio? A few questions I'm rather hazy on specifically are:

有没有人有关于dll的良好资源以及它们在Visual Studio中的使用/生成方式?我特别朦胧的一些问题是:

  • How refresh files work
  • 刷新文件的工作原理

  • How dll version numbers are generated
  • 如何生成DLL版本号

  • The difference between adding a reference by project vs browsing for the specific dll
  • 项目添加引用与特定dll浏览之间的区别

Any other tips are welcome as well.

欢迎任何其他提示。

2 个解决方案

#1


10  

.NET DLL's

The general term for a .NET DLL is an assembly. They are a single atomic unit of deployment and consist of one or more CLR 'modules' (for most developers usually just one unless they are combining compiler output from two or more languages for example). Assemblies contain both CIL code and CLR metadata such as the assembly manifest.

.NET DLL的一般术语是程序集。它们是单个原子部署单元,由一个或多个CLR“模块”组成(对于大多数开发人员通常只有一个,除非他们将两个或更多语言的编译器输出组合在一起)。程序集包含CIL代码和CLR元数据,例如程序集清单。

.refresh Files

.refresh files are simply text files that tell VS where to check for new builds of referenced dll's. They are used in file based web projects where there isn't a project file to store this info.

.refresh文件只是简单的文本文件,告诉VS在哪里检查引用的dll的新版本。它们用于基于文件的Web项目,其中没有用于存储此信息的项目文件。

Version Numbers

.NET Assembly version numbers are generated by an assembly scoped attribute AssemblyVersion which is usually found in a source file named 'AssemblyInfo.cs' (found under a project folder named 'Properties' from VS2005 onwards). Version numbers are comprised of major.minor.build.revision, for example -

.NET程序集版本号由程序集范围属性AssemblyVersion生成,该属性通常位于名为“AssemblyInfo.cs”的源文件中(位于VS2005以后名为“Properties”的项目文件夹下)。版本号由major.minor.build.revision组成,例如 -

[assembly: AssemblyVersion("1.0.0.0")]

AssemblyVersion is used as part of an assembly's identity (i.e. in its strong name) and plays an important role in the binding process and during version policy decisions.

AssemblyVersion用作程序集标识的一部分(即以其强名称),并在绑定过程和版本策略决策期间发挥重要作用。

For example if I had two assemblies of the same name in the GAC then the AssemblyVersion attribute would differentiate them for the purposes of loading a specific version of the assembly.

例如,如果我在GAC中有两个同名的程序集,那么AssemblyVersion属性会区分它们以便加载特定版本的程序集。

AssemblyVersion number can be fixed and incremented manually or you can allow the compiler to generate the build and revision numbers for you by specifying:

AssemblyVersion编号可以手动修复和递增,或者您可以允许编译器通过指定以下内容为您生成构建和修订号:

[assembly: AssemblyVersion("1.0.*")] - generates build and revision number
[assembly: AssemblyVersion("1.0.0.*")] - generates revision number

[assembly:AssemblyVersion(“1.0。*”)] - 生成构建和修订号[assembly:AssemblyVersion(“1.0.0。*”)] - 生成修订号

If the AssemblyVersion attribute is not present then the version number default to '0.0.0.0'.

如果AssemblyVersion属性不存在,则版本号默认为“0.0.0.0”。

The value of the AssemblyVersion attribute becomes part of an assembly's manifest, the AssemblyFileVersion attribute value does not.

AssemblyVersion属性的值成为程序集清单的一部分,而AssemblyFileVersion属性值则不会。

The AssemblyFileVersion attribute is used to embed a Win32 file version into the DLL. If this is not present then AssemblyVersion is used. It has no bearing on how the .NET assembly loader/resolver chooses which version of an assembly to load.

AssemblyFileVersion属性用于将Win32文件版本嵌入到DLL中。如果不存在则使用AssemblyVersion。它与.NET程序集加载器/解析程序如何选择加载哪个版本的程序集无关。

Project References vs Browsing For DLL

项目引用与浏览DLL

If you're adding a project reference it means that the referenced project will be part of your solution. This makes debugging simpler by being able to step directly into your referenced project's code. If you only add a dll reference then you don't have the benefits of the project being part of the solution and being able to step into the code within the solution.

如果您要添加项目引用,则意味着引用的项目将成为您的解决方案的一部分。这使得调试更简单,因为它能够直接进入您引用的项目代码。如果您只添加一个dll引用,那么您将无法获得项目作为解决方案一部分的好处,并且能够进入解决方案中的代码。

#2


5  

See the question on DLL information for some background.

有关某些背景,请参阅有关DLL信息的问题。

Version numbers for unmanaged DLLs are stored in the DLL's rc file, same as for an exe. For managed DLLs I believe it uses AssemblyFileInfo attribute, usually in AssemblyInfo.cs for a Visual Studio generated project:

非托管DLL的版本号存储在DLL的rc文件中,与exe相同。对于托管DLL,我认为它使用AssemblyFileInfo属性,通常在AssemblyInfo.cs中用于Visual Studio生成的项目:

[assembly: AssemblyFileVersion("1.0.0.0")]

If you add the reference by project then VS will be able to copy the correct flavour (debug/release) of the referenced assembly to your output directory. It can also use this information to implicitly add a dependency between the projects so it builds then in the right order.

如果按项目添加引用,则VS将能够将引用的程序集的正确flavor(调试/发布)复制到输出目录。它还可以使用此信息隐式添加项目之间的依赖关系,以便按正确的顺序构建它们。

#1


10  

.NET DLL's

The general term for a .NET DLL is an assembly. They are a single atomic unit of deployment and consist of one or more CLR 'modules' (for most developers usually just one unless they are combining compiler output from two or more languages for example). Assemblies contain both CIL code and CLR metadata such as the assembly manifest.

.NET DLL的一般术语是程序集。它们是单个原子部署单元,由一个或多个CLR“模块”组成(对于大多数开发人员通常只有一个,除非他们将两个或更多语言的编译器输出组合在一起)。程序集包含CIL代码和CLR元数据,例如程序集清单。

.refresh Files

.refresh files are simply text files that tell VS where to check for new builds of referenced dll's. They are used in file based web projects where there isn't a project file to store this info.

.refresh文件只是简单的文本文件,告诉VS在哪里检查引用的dll的新版本。它们用于基于文件的Web项目,其中没有用于存储此信息的项目文件。

Version Numbers

.NET Assembly version numbers are generated by an assembly scoped attribute AssemblyVersion which is usually found in a source file named 'AssemblyInfo.cs' (found under a project folder named 'Properties' from VS2005 onwards). Version numbers are comprised of major.minor.build.revision, for example -

.NET程序集版本号由程序集范围属性AssemblyVersion生成,该属性通常位于名为“AssemblyInfo.cs”的源文件中(位于VS2005以后名为“Properties”的项目文件夹下)。版本号由major.minor.build.revision组成,例如 -

[assembly: AssemblyVersion("1.0.0.0")]

AssemblyVersion is used as part of an assembly's identity (i.e. in its strong name) and plays an important role in the binding process and during version policy decisions.

AssemblyVersion用作程序集标识的一部分(即以其强名称),并在绑定过程和版本策略决策期间发挥重要作用。

For example if I had two assemblies of the same name in the GAC then the AssemblyVersion attribute would differentiate them for the purposes of loading a specific version of the assembly.

例如,如果我在GAC中有两个同名的程序集,那么AssemblyVersion属性会区分它们以便加载特定版本的程序集。

AssemblyVersion number can be fixed and incremented manually or you can allow the compiler to generate the build and revision numbers for you by specifying:

AssemblyVersion编号可以手动修复和递增,或者您可以允许编译器通过指定以下内容为您生成构建和修订号:

[assembly: AssemblyVersion("1.0.*")] - generates build and revision number
[assembly: AssemblyVersion("1.0.0.*")] - generates revision number

[assembly:AssemblyVersion(“1.0。*”)] - 生成构建和修订号[assembly:AssemblyVersion(“1.0.0。*”)] - 生成修订号

If the AssemblyVersion attribute is not present then the version number default to '0.0.0.0'.

如果AssemblyVersion属性不存在,则版本号默认为“0.0.0.0”。

The value of the AssemblyVersion attribute becomes part of an assembly's manifest, the AssemblyFileVersion attribute value does not.

AssemblyVersion属性的值成为程序集清单的一部分,而AssemblyFileVersion属性值则不会。

The AssemblyFileVersion attribute is used to embed a Win32 file version into the DLL. If this is not present then AssemblyVersion is used. It has no bearing on how the .NET assembly loader/resolver chooses which version of an assembly to load.

AssemblyFileVersion属性用于将Win32文件版本嵌入到DLL中。如果不存在则使用AssemblyVersion。它与.NET程序集加载器/解析程序如何选择加载哪个版本的程序集无关。

Project References vs Browsing For DLL

项目引用与浏览DLL

If you're adding a project reference it means that the referenced project will be part of your solution. This makes debugging simpler by being able to step directly into your referenced project's code. If you only add a dll reference then you don't have the benefits of the project being part of the solution and being able to step into the code within the solution.

如果您要添加项目引用,则意味着引用的项目将成为您的解决方案的一部分。这使得调试更简单,因为它能够直接进入您引用的项目代码。如果您只添加一个dll引用,那么您将无法获得项目作为解决方案一部分的好处,并且能够进入解决方案中的代码。

#2


5  

See the question on DLL information for some background.

有关某些背景,请参阅有关DLL信息的问题。

Version numbers for unmanaged DLLs are stored in the DLL's rc file, same as for an exe. For managed DLLs I believe it uses AssemblyFileInfo attribute, usually in AssemblyInfo.cs for a Visual Studio generated project:

非托管DLL的版本号存储在DLL的rc文件中,与exe相同。对于托管DLL,我认为它使用AssemblyFileInfo属性,通常在AssemblyInfo.cs中用于Visual Studio生成的项目:

[assembly: AssemblyFileVersion("1.0.0.0")]

If you add the reference by project then VS will be able to copy the correct flavour (debug/release) of the referenced assembly to your output directory. It can also use this information to implicitly add a dependency between the projects so it builds then in the right order.

如果按项目添加引用,则VS将能够将引用的程序集的正确flavor(调试/发布)复制到输出目录。它还可以使用此信息隐式添加项目之间的依赖关系,以便按正确的顺序构建它们。