编译期间的程序集解析顺序 [英] Order of assembly resolution during compile

查看:21
本文介绍了编译期间的程序集解析顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS 2008 如何确定在何处查找在编译应用程序期间使用的程序集?必须使用某种顺序.工具\设置或其他东西中是否使用了某些东西?我正在寻找在编译过程中程序集解析发生的顺序.

How does VS 2008 determine where to look for assemblies used during compiling of applications? There must be some order used. Is there something that is used in the Tools\Settings or something else? I am looking for the order of which assemblies resolution occurs during the compilation process.

推荐答案

决定顺序的并不是 VS 2008,而是编译器.我知道您没有指定语言,但我将使用 C# 作为示例(我相信许多其他语言也可以作为很好的示例).如果您使用的是 C#,编译器首先处理 csc.rsp(位于 csc.exe 旁边的响应文件),然后处理命令行/r: 选项.操作顺序决定引用哪个程序集.因此,首先找到 csc.rsp 中的程序集引用,然后找到命令行程序集.这是编译时.

It really isn't VS 2008 that determines the order, but rather the compiler. I know you didn't specify a language, but I'll use C# as an example (I'm sure many other languages would serve as good examples too). If you were using C#, the compiler processes csc.rsp (response file located beside csc.exe) first and then processes command-line /r: options. The order of operations determine which assembly is referenced. Therefore, assembly references in csc.rsp are found first and then command-line assemblies are found. This was compile-time.

以下是 C# 响应文件的文档:

Here's the docs for the C# response file:

http://msdn.microsoft.com/en-us/library/8a1fs1tb(VS.71).aspx

以下是 C# 命令行编译器选项的文档:

Here's the docs for C# command-line compiler options:

http://msdn.microsoft.com/en-us/library/2fdbz5xd(VS.71).aspx

如果您想使用自定义响应文件,则必须使用命令行编译器.否则,您添加到项目的引用文件夹的引用决定了在 VS 中构建时命令行上显示的内容.您可以通过执行构建并查看输出窗口(Ctrl+W+O)来查看这些引用出现在命令行上的顺序.

You would have to use the command-line compiler if you wanted to use a custom response file. Otherwise, the references you add to a project's references folder determine what appears on the command-line when you build in VS. You can see the order that these references appear on the command-line by doing a build and looking at the Output Window, Ctrl+W+O.

运行时程序集绑定也不是由 VS 决定的,而是由 CLR 决定的.一个简单的总结是,CLR 会搜索程序集之前是否已加载到内存中,然后检查 GAC,然后根据代码中是否存在对 Load 的显式调用,然后是 codeBase 的配置文件设置来执行探测,然后是应用程序文件夹下的一组文件夹,这些文件夹以程序集的 exe 或 dll 版本命名.这是 MSDN 链接:

Run-time assembly binding is not determined by VS neither, but rather by the CLR. A quick summarization is that the CLR searches to see if an assembly was previously loaded into memory, the checks the GAC, and then performs probing based on whether there was an explict call to Load in the code, then a config file setting for codeBase, and then a set of folders under the application folder that are named for either exe or dll versions of the assembly. Here's the MSDN link:

http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx

你问这个问题的事实让我怀疑你的动机是否是为了解决程序集绑定问题..NET Framework SDK 中有一个工具,称为程序集绑定日志查看器 (Fuslogvw.exe),用于帮助解决这些类型的问题:

The fact that you're asking this question makes me wonder if your motivation is to solve an assembly binding issue. There is a tool in the .NET Framework SDK, called the Assembly Binding Log Viewer (Fuslogvw.exe) for helping resolve these types of problems:

http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx

网络上使用程序集绑定和 Fusion 日志查看器的一些最佳资源是 Richard Grimes 的 Fusion Workshop:

A couple of the best resources on the net for working with assembly bindings and Fusion log viewer are Richard Grimes' Fusion Workshop:

http://www.grimes.demon.co.uk/workshops/fusionWS.htm

几年前,CLR 团队成员 Suzanne Cook 发表了一系列关于 CLR 绑定的精彩帖子:

A few years back, Suzanne Cook, who was a member of the CLR team, did an excellent series of posts on CLR binding:

http://blogs.msdn.com/suzcook/default.aspx

希望这会有所帮助,

这篇关于编译期间的程序集解析顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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