简体   繁体   English

.Net项目的程序集依存关系

[英]Assembly dependencies with .Net projects

If I have an assembly (A) which references another assembly (B). 如果我有一个引用另一个程序集(B)的程序集(A)。 I want to reference A in a project, I add the reference and it copies A into my BIN directory. 我想在项目中引用A,添加引用并将其复制到我的BIN目录中。 It does not copy B as well, even though A depends on it, so the code doesn't compile. 即使A依赖它,它也不会复制B,因此代码不会编译。 How can I set things up so that whenever I reference A, both A and B get copied to my bin directory? 如何设置内容,以便每当我引用A时,A和B都被复制到我的bin目录中?

In Visual Studio, add each project to the same solution. 在Visual Studio中,将每个项目添加到相同的解决方案。 Ensure you use Project References instead of direct file references (ie browsing for the assembly). 确保您使用项目引用而不是直接文件引用(即浏览程序集)。

I dont think there is any way around what you ask other than to explicitly add both. 我认为除了明确地将两者都添加外,没有其他方法可以解决您的要求。 I dont think however adding projects for the sake of getting references copied is a viable solution to the issue. 我不认为但是为了复制参考添加项目是解决该问题的可行方法。 Not all projects that a solution depends on should necassarily be added to the solution. 并非必须将解决方案所依赖的所有项目都添加到解决方案中。 This would completely depdend on your overall project structure, processes, source control, division of labour, etc 这将完全取决于您的整体项目结构,流程,源代码控制,分工等

同时引用A和B。

Unfortunately you'll have to manually add both. 不幸的是,您必须手动添加两者。 This is what happens to me as well whenever I use pre-3.5 versions of NHibernate: it requires both log4net and Iesi.Collections assemblies. 每当我使用NHibernate 3.5之前的版本时,这也会发生在我身上:它需要log4net和Iesi.Collections程序集。 So I have no choice but to manually include a reference to both in all my solutions that implement NHibernate. 因此,我别无选择,只能在实现NHibernate的所有解决方案中手动包括对两者的引用。

This is more of an issue, of course, if you only have the DLLs. 如果您只有DLL,那么这当然是一个更大的问题。 If it's a project that you have a codebase to Visual Studio itself will warn you beforehand that the references are missing. 如果这是一个项目,您具有Visual Studio本身的代码库,则会事先警告您引用丢失。

如何将它们添加到Global Assembly Cache?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM