解决 C# 和 C++/CLI 项目之间的循环项目依赖性?
我们有一个包含多个项目的解决方案。
在一种特殊情况下,我们有两个项目: 1) 完成大部分工作的AC#项目 2) 充当某些本机 C++ 代码中间人的 C++/CLI 项目
C# 代码调用 C++ 包装器,一切都很好。
但是,我们正在引入一些新功能。在 C++ 包装器(项目 #2)的托管端,它需要项目 #1 中的托管 C# 代码中的一些静态方法。但是,Visual Studio 不会让我们相互关联这两个项目,因为它抱怨循环项目引用。然而,没有循环类引用。
有没有不需要第三个项目作为中介的问题的解决方案?
We have a solution with a number of projects.
In one particular case, we have two projects:
1) A C# project that does most of the work
2) A C++/CLI project that acts as a go-between to some native C++ code
The C# code calls into the C++ wrapper, all is well.
However, there is some new functionality that we are pulling in. On the managed side of the C++ wrapper (project #2), it requires some static methods in the managed C# code that is in project #1. However, Visual Studio will not let us mutually associate these two projects as it complains of a circular project reference. There is no circular class reference however.
Is there any solution to this problem that does not require a 3rd project as an intermediary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以让 A 依赖于 B。为简单起见,假设 A.EXE 依赖于 B.DLL。然后,当 A 最初调用 B 时,它可以给它一个在 B 中定义的某种类型或接口的对象,然后 B 可以转身并在稍后的某个时刻回调到 A。
换句话说,B 定义了一个基类或接口,例如“我想要只有 A 可以做的事情”,但不实现它。然后让A实现它,传递给你,然后调用它。这可以绕过循环依赖,而无需第三个项目。这适用于任何一对托管项目。
You can have A depend on B. For simplicity lets say A.EXE depends on B.DLL. Then when A initially calls B, it can give it an object of some type or interface that is defined in B and then B can turn around and call back into A at some later point.
In other words, B defines a base class or interface like "I want something that only A can do" but don't implement it. Then let A implements it, passes it to you, and calls it. This gets around the circular dependency without a third project. This applies to any pair of managed projects.