在同一解决方案中处理C#和VB.net项目 [英] Dealing with C# and VB.net Projects in same solution

查看:199
本文介绍了在同一解决方案中处理C#和VB.net项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个c#项目中,在这个项目中,我引用(使用项目引用)另一个用vb.net编写的类库.

I am in a c# project, in this project I reference (using a project reference) another class library written in vb.net.

现在,当我右键单击并查看课程的定义时.它并没有带我到vb.net项目中的确切源代码,而是带我到了vb.net类的动态生成的c#表示形式.

Now, when I right click and view definition on the class. It doesn't take me to the exact source code in the vb.net project, instead it takes me to a dynamically generated c# representation of the vb.net class.

我从vb.net项目开始,然后引用ac#项目,以相反的方式尝试了该实验,这次是在右键单击视图定义上,它将我带到代码资源管理器,因此,同样,不是原始代码进行编辑.

I've tried the experiment in reverse, starting with a vb.net project, and referencing a c# project, this time on a right click view definition, it takes me to the code explorer, so again, not the original code for editing.

如果两个项目都使用相同的语言,则一切工作都很好.

If both projects are the same language, everything works like nicely.

对此有解释吗?可能是一种允许在不同语言的项目之间轻松进行代码导航的解决方案吗?

Is there an explanation for this? And possibly a solution to allow easy code navigation between projects of different languages?

要复制:

  1. 创建空白解决方案
  2. 添加一个c#类库
  3. 添加vb.net类库
  4. 在vb.net类库中,class1-创建任何旧方法. (可选)
  5. 在c#类中,添加对vb.net类的引用,例如:

  1. Create a blank solution
  2. Add a c# class library
  3. Add a vb.net class library
  4. In the vb.net class library, class1 - create any old method. (optional)
  5. In the c# class, add a reference to the vb.net class, for example:

VBClassLibrary.VBClass myVBClass =新的VBClassLibrary.VBClass();

VBClassLibrary.VBClass myVBClass = new VBClassLibrary.VBClass();

现在,右键单击VBCLass并选择转到定义".

Now, right click on VBCLass and select "Go To Definition".

请注意最终的位置....

Notice where you end up....

推荐答案

您在这里没有做错任何事情.这是Visual Studio设计方式的不幸副作用.当您有两个使用不同语言的项目时,它们之间的引用并不像项目引用那样,而是类似于文件引用.

There is nothing you are doing wrong here. This is an unfortunte side effect of how Visual Studio is designed. When you have two projects in different languages a reference between them does not behave like a project reference but instead resembles a file reference.

相同语言的项目到项目"引用共享一种语言服务.因此,它可以控制所有代码,并可以提供特殊的实时内容好处.最主要的是goto定义和即时智能感知.如今,Visual Studio中没有功能允许语言服务像您所希望的那样跨参考边界相互通信.

Project to Project references of the same language share a single language service. Hence it is in control of all of it's code and can provide special live content benefits. The primary one being the goto definition and instant intellisense. There is just no facility in Visual Studio today to allow language services to communicate with each other across the reference boundary like you desire.

这篇关于在同一解决方案中处理C#和VB.net项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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