是否有可能使循环依赖在Visual Studio中的装配水平?会互相依赖组件,甚至可能吗?能使、组件、水平、Studio

2023-09-03 01:58:23 作者:且将桃花换酒钱

这可能听起来像一个愚蠢的问题,但我想给它一个镜头呢。

因此​​,在Visual Studio中,你不能有两个项目X和Y使得X引用Y和Y引用的X.

在一般情况下,我完全可以理解为一个循环依赖可能会产生问题,因为各种各样的原因。

这是真的不是的可能的编译两个项目是相互依存的这种方式?在我看来,它必须是可能的,因为(在我的脑海 - 也许我的完全的关闭基地这个)有两个互相依赖的组件是真的不的这样从具有两个相互依存类不同 - 其中的是的合法的可以的编译

这将是有意义的我,如果你说,两个组件不能依赖于对方,因为编译器无法编译前一个其他的;但它似乎你可以在同一个组件内进行了两个类相同的说法,并明确了编译器可以使用此方案处理就好了。

基本上我问的原因是不是我有些绝望的愿望,做这件事情,我知道一般是不明智的反正。具体来说,我不知道,因为这将是很好,如果我能有两个项目 - 比如,MyProjectCS和MyProjectVB - 存在基本上作为一个单元的两个互相依赖的部分,只分开,因为某些部分是写在C#和其他部分是写在VB.NET。

所以,我的问题是(哎呀,三倍):

是否有可能启用此行为(在Visual Studio中,或其他地方,对于这个问题)? 如果这是不可能的任何IDE,它是至少的理论上的可能,或可能相互依存的组件可能不存在? 如果它甚至不是理论上的可能,为什么不呢?换句话说,如何一个组件内的相互依存code不同的互相依赖的组件? 解决方案

我不知道该怎么做,在一个IDE;然而它可以通过compilicated构建过程来构建。

用 Visual Studio 2015 编写第一个 Windows程序

您需要:

大会A 在组件B 在存根组件B

在这里存根组件B包含公共类和组件B的公共方法和相同的程序集信息。*和引用相同的公钥。

构建顺序:

在编译存根组件B 复制存根组件B至组件B的输出目录 在构建组件A 在构建集B

请注意,你不能在方法签名类型的直接环路参考;但是你可以通过对象铸有有效的循环。

请注意:

ILASM可以编译真正的相互递归集为不知它可以解决没有在编译时存在的类型。

进一步指出:

在aspnet_compiler似乎能够混合不同的语言在同一个项目(谁知道)。

This probably sounds like a stupid question, but I'm going to give it a shot anyway.

So in Visual Studio, you can't have two projects X and Y such that X references Y and Y references X.

In general, I can totally understand how having a circular dependency can be problematic, for a variety of reasons.

But is it really not possible to compile two projects that are interdependent in this way? It seems to me that it must be possible, since (in my mind -- maybe I'm completely off-base about this) having two mutually dependent assemblies is really not so different from having two mutually dependent classes -- a case which is legal and can be compiled.

It would make sense to me if you said, "two assemblies cannot depend on each other because the compiler could not compile one before the other"; except that it seems you could make the same argument for two classes within the same assembly, and clearly the compiler can deal with this scenario just fine.

Basically the reason I'm asking is not that I have some desperate desire to do this thing that I know is generally ill-advised anyway. Specifically I'm wondering because it would be nice if I could have two projects -- say, MyProjectCS and MyProjectVB -- that existed basically as two mutually dependent parts of a single unit, and were only separate because certain parts were written in C# and other parts were written in VB.NET.

So, my question is (yikes, three-fold):

Is it possible to enable this behavior (in Visual Studio, or elsewhere, for that matter)? If it's not possible within any IDE, is it at least theoretically possible, or could mutually dependent assemblies not possibly exist? If it's not even theoretically possible, why not? In other words, how are mutually dependent assemblies different from mutually dependent code within a single assembly?

解决方案

I don't know how to do it in an IDE; however it is possible to construct via a compilicated build process.

You will need:

Assembly A Assembly B Stub Assembly B

where Stub Assembly B contains the public classes and public methods of Assembly B and the same AssemblyInfo.* and references the same public key.

Build order:

Compile Stub Assembly B Copy Stub Assembly B to the output dir of Assembly B Build assembly A Build assembly B

Notice that you cannot have direct loop references of the types in the method signatures; however you can have effective loops by casting through object.

NOTE:

ilasm can compile true mutually recursive assemblies as somehow it can resolve types that don't exist at compile time.

FURTHER:

the aspnet_compiler seems to be able to mix different languages in the same project (who knows how).