开发者

Dealing with C# and VB.net Projects in same solution

开发者 https://www.devze.com 2023-01-21 07:20 出处:网络
I am in a c# project, in this project I reference (using a project reference) another class library written in vb.net.

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

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

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?

To reproduce:

  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 = new VBClassLibrary.VBClass();

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

Notice where you end up....


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.

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.


For "goto definiton" you can use instead "navigate to" (ctrl + commma)

0

精彩评论

暂无评论...
验证码 换一张
取 消