Solving circular project dependency between C# and C++/CLI projects?

感情迁移 提交于 2019-12-12 17:20:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5983291/solving-circular-project-dependency-between-c-sharp-and-c-cli-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!