当您在.NET中添加DLL的引用在项目中会发生什么 [英] What happens when you add a reference of a dll in your project in .net

查看:133
本文介绍了当您在.NET中添加DLL的引用在项目中会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET类库项目说,当建将创建一个DLL即A.DLL,A。我有另外一个项目说B和该项目包含DLLA.DLL的参考。到底发生了什么,当我加入A在B中的参考?谁能告诉我在编译时和运行时会发生什么?

I have a class library project in .net say "A" which when built will create a dll namely "A.dll". I have another project say "B" and this project contains the reference of the dll "A.dll". What exactly happens when I add the reference of A in B? Can anybody please tell me what happens both during compile time as well as during runtime?

推荐答案

A.DLL所使用的编译器,结合使用的任何指令和别名,进行类型解析。当发现的那些类型,标记物为在A.DLL类型的包含在IL。如果A.DLL则根本不使用参考将被删除。

A.dll is used by the compiler, in combination with any using directives and aliases, to perform type resolution. When those types are found, a marker to the type in A.dll is included in the IL. If A.dll is not used at all the reference is silently dropped.

没有code复制 - 只有合格的名字等 - 因此你还需要部署A.DLL旁边的B.DLL(或在GAC)

No code is copied - only qualified names etc - hence you still need to deploy A.dll alongside your B.dll (or in the GAC).

在运行时,当标记在A.DLL类型被发现,融合尝试加载并验证A.DLL(有复杂的规则和可选的间接这里) - 一旦装好了解决指定的类型,并继续(使用从A.DLL的类型)。

At runtime, when the marker to a type in A.dll is found, "fusion" attempts to load and verify A.dll (there are complex rules and optional indirections here) - once loaded it resolves the type specified and continues (using the type from A.dll).

这篇关于当您在.NET中添加DLL的引用在项目中会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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