类库引用问题 [英] Class library reference problem

查看:191
本文介绍了类库引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个类库,并使用其默认命名空间为系统。这里假设我创建一个通用的数据结构,说的PriorityQueue,并把它在System.Collections.Generic命名空间。

I am building a class library and using its default namespace as "System". There suppose I am creating a generic data structure say PriorityQueue and putting it under System.Collections.Generic namespace.

现在,当我引用该库从另一个项目,我看不到的PriorityQueue在System.Collections.Generic命名空间了。虽然库是在该项目中引用我不能访问任何类的。

Now when I am referencing that library from another project, I can't see PriorityQueue under "System.Collections.Generic" namespace anymore. Though the library is referenced in that project I can not access any of the classes in it.

我的问题是mscorlib程序和System.dll中有着相似的命名空间,但仍来自装配类是可访问的,但为什么不是我?如果我在我的类库放在一个公共类下System.Collections.Generic命名空间,并指该库的一个项目,并使用类似使用System.Collections.Generic的声明,还是我为什么不能访问我的课吗?

My question was mscorlib and System.dll share similar namespaces, but still classes from both the assembly is accessible, but why can't mine? If I put a public class under System.Collections.Generic namespace in my class library and refer that library in a project and use a statement like "using System.Collections.Generic", still why I can't access my class there?

这是一个实验我做的,我知道用系统命名空间是不鼓励自定义类库,但我想知道背后的为什么我不能访问我的课在这种特殊情况下的原因是什么?

This was an experimentation I did, I know using System namespace is not encouraged in custom class library, but I want to know the reason behind why I can't access my class in this special case?

请人揭示它的一些情况。

Please someone shed some light on it.

PS:上次我问类似的问题,但把它错误,所以人们得到了误会,我没有得到我的答案。这一次,我试图把它正确的尽我所能。很抱歉的误解。

PS: Last time I asked similar question but put it wrongly, so people got misunderstood and I didn't get my answer. This time I am trying to put it correctly as far as I can. Sorry for the misunderstanding.

推荐答案

这个问题出现在使用了工程案例,而不是出现一个集引用。

The problem appears to arise when you use a "Project Reference" rather than an "Assembly Reference".

使用一个集引用。

这是我不愿意钻研的根本原因个坏主意。

This is such a bad idea that I am reluctant to delve into the underlying reasons.

更新

我猜测,当您使用项目引用(从你的系统命名空间中的项目),问题便产生了建立不知道它应该可以解决从引用的项目的依赖,而是它试图从一个解决这个问题的组件一个已经引用即System.dll中。这显然​​并不在System.dll中存在。如果添加一个直接引用DLL的内置版本,该版本将能够解决它。

I am guessing that when you use a project reference (from your System namespace project), the issue arises as the build does not know that it should resolve the dependency from your referenced project, but instead it attempts to resolve it from one of the assemblies that is already referenced i.e. System.dll. It obviously does not exist in System.dll. If you add a direct reference to a built version of your dll, the build will be able to resolve it.

这篇关于类库引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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