如何在 .NET/C#/VS2008 中的项目之间共享命名空间。接收错误:“您是否缺少程序集引用?”
当后续项目将引用两个名称空间时,在两个项目之间共享名称空间的协议是什么?
显然这是可能的(系统,mscorlib)...
根据我尝试过的事情,我遇到了不同的错误。现在我有两个项目 Blueprint 和 Domain 共享 MainApp 命名空间(例如 Blueprint 具有 MainApp.IEntity,Domain 具有 MainApp.EntityImpl)。它们都被第三个项目存储库引用。存储库依赖于 IRepository(在蓝图中)和 EntityImpl(在域中)。首先构建蓝图,然后是域,然后是存储库。对于 Domain 项目中的每个类的引用,我都会收到“命名空间‘MainApp’中不存在类型或命名空间名称 Domain(您是否缺少程序集引用?)...
程序集引用都是正确的。
我确保所有项目之间有一个通用的程序集名称,并在其中一个项目中添加一个 AssemblyInfo 类,并使用“添加对根的链接引用”这没有任何作用,因此我删除了它< /strong>。
我可以合并这两个项目,但在某些情况下,我感谢你们提供的任何指导,
蓝图没有项目间引用, 域依赖于蓝图 存储库依赖于蓝图和域
我已经完成了所有删除 dll、构建重建、清理重复的工作。没有骰子。
What is the protocol to share a namespace between two projects when consequential projects will reference both of the namespaces?
Obviously this is possible (System, mscorlib)...
I've gotten different errors depending on the things I've tried. Right now I have two projects Blueprint and Domain that share the MainApp namespace (for instance Blueprint has MainApp.IEntity and Domain has MainApp.EntityImpl). They are both referenced by a third project, Repositories. Repositories relies on both IRepository (in Blueprint) and EntityImpl (in Domain). Blueprint builds first, followed by Domain and then Repositories. For every reference to a class in the Domain project, I get a "The type or namespace name Domain does not exist in the namespace 'MainApp' (are you missing an assembly reference?)...
The assembly references are all correct.
I made sure there was a common assembly name between all the projects and adding an AssemblyInfo class in one of them with 'add link references to the root. This did nothing, and so I removed it.
I could merge these two projects, but there are circumstances in which that would be detrimental. I appreciate any guidance y'all can offer.
In response to the comment, Blueprint has no inter-project references,
Domain has a dependency on Blueprint
Repositories has a dependency on Blueprint and Domain
I have done all the deleting the dlls, building rebuilding cleaning repeating..no dice..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我无法解释为什么,但我有一个项目,其中有两个类库项目定义相同的命名空间并使用框架 3.5。我在使用 NET Framework 4.0 客户端配置文件的项目中引用了它们,并得到了您得到的错误。当将其设置为 NET Framework 4.0 时,它起作用了。
I can't explain why, but I have a project with two class library projects defining same namespace and using framework 3.5. I referred them in a project using NET Framework 4.0 client profile and got the error you got. When setting it to NET Framework 4.0 it worked.
打开 Reflector 中的两个 dll扁平化命名空间(视图 -> 选项 -> 浏览器 -> 扁平化命名空间)。
看看这是否可以帮助您找出问题的原因。
Open both the dlls in reflector & flatten the namespaces (view -> options -> browser -> flatten namespaces).
See if that helps you figure out the reason of the problem.
我最终通过将代码复制到不同的解决方案来解决这个问题。回想起来,我确信这是不必要的。回想起来,我认为通过删除 bin 和 obj 文件夹中的所有内容可以解决问题。
I ended up resolving this by copying the code to a different solution. In retrospect I'm sure this was unnecessary. Looking back, I think the problem would have been fixed by deleting everything from the bin and obj folders.
我刚刚遇到这个问题。您需要确保所有项目都是相同的版本。许多矿场是 .net 4.0 和 4.5 的组合;让它们全部引用 4.5 为我解决了这个问题。
I just ran into this issue. You need to make sure all your projects are the same version. A number of mines were a combination of .net 4.0 and 4.5; making them all reference to 4.5 fixed the issue for me.