解决C#和C ++ / CLI项目之间的循环项目依赖关系? [英] Solving circular project dependency between C# and C++/CLI projects?

查看:287
本文介绍了解决C#和C ++ / CLI项目之间的循环项目依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有许多项目的解决方案。

We have a solution with a number of projects.

在一个特殊情况下,我们有两个项目:
1)的工作
2)一个C ++ / CLI项目,作为一个本地C ++代码之间的连接

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

C#代码调用C ++包装器,一切都很好。

The C# code calls into the C++ wrapper, all is well.

但是,有一些新的功能,在C ++封装器(项目#2)的托管方面,它需要一些静态方法在项目#1中的受管C#代码中。但是,Visual Studio不会让我们相互关联这两个项目,因为它抱怨循环项目引用。但没有循环引用。

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?

推荐答案

你可以有A依赖B.为了简单起见,A.EXE依赖B.DLL。然后当A最初调用B时,它可以给它一个在B中定义的类型或接口的对象,然后B可以转向并在稍后的点回调到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.

换句话说,B定义了一个基类或接口,像我想要只有A可以做的东西,但不实现它。然后让A实现它,将它传递给你,并调用它。这绕过循环依赖,没有第三个项目。这适用于任何受管理项目对。

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.

这篇关于解决C#和C ++ / CLI项目之间的循环项目依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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