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

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 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:
Create a blank solution
Add a c# class library
Add a vb.net class library
In the vb.net class library, class1 - create any old method. (optional)
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)

Related

Debugging in Delphi (RAD Studio) - viewing class properties in Watch List

When I set breakpoint in code and I want to check properties of some class in RAD Studio 2009 (Delphi project) I cannot see them in Watch List or in Local Variables list.
All I see is Pointer (Address) as TSomeClass.
Why I see this? I use also Visual Studio where it is amazing - I can see Properties and all members of some class.
I am sure the same worked in some older versions of Delphi too (There was small [+] which could be expanded to see class properties).
Is there some settings for this (I have turned off optimizations, turned on Debug...)
Maybe this is a trivial question but I am not able to continue with my project as this is really uncomfortable for me.
You are not comparing like with like. The variable in the Delphi screenshot is an interface. It has no data members, only methods. The debugger won't call methods to display tooltips, etc. since methods can have side-effects. You don't want your tooltips changing the meaning of the program.
On the other hand, your VS example is a class with data members. These are displayed in the debugger nicely in VS, and in Delphi for that matter.

Visual Studio plug in to jump to test class

I was wondering if there is a plugin that allows me to jump directly to the test for the current class (Or create it if it doesn't exist).
I guess this should be based on the convention that the test project is named like the project being tested + "test" and the test class is named like the class being tester + "test".
A feature like that would really help in projects with many files and foldes, where scrolling the solution explorer to find the associated test project can be quite annoying.
how about NCrunch? This tool will show you, per method, which and how many tests are covering it:
I did manage to find a few extensions on visualstudiogallery.com, but ended up writing my own plugin for this. Its not perfect, but i does what I needed.
If anyone else would like, its available for free at testlocator.eqa.dk
In Visual Studio you can Shift+F12 on any class or method definition to find all references. Although the resulting list Studio is not very convenient, but a starting point. Using a tool like DevExpress CodeRush or ReSharper lets you sort and filter by namespace, project, file, etc.
If you happen to use ReSharper, it has a TestLinker plugin.
It does the job pretty well.
Basic shortcut: Ctrl+Alt+F7.
Goto Related Files is extended with navigation points to production/test classes.
New shortcuts ReSharper_GotoAllLinkedTypes and ReSharper_GotoLinkedTypesWithDerivedName (assignable via keyboard options) that jumps between linked types. In case of multiple linked types, a dedicated popup menu is shown, which can also be displayed in Find Results window.

Intellisense is lost for outside classes in Visual Studio

I have a file of a user control but it's not in a project, It's just read by a webpart in sharepoint and I was editing it but suddenly the AutoComplete for classes and variables like controls, SQL .. were gone. Only the common keywords are available like if, int, while ...
How can I get them back?
When you just have a single file, I believe Visual Studio just opens it in the code editor, and not the IDE/Compiler. The editor is just syntax highlighting basically, though you do have the drop downs available to navigate subclasses and methods. As when you're dealing with projects, it does use the IDE/Compiler, so Intellisense is available as well as full editor/ide features for that language.
Create a new empy ASP.NET Website and then add existing item and choose this user control.

Visual Studio ‘Go To Definition’ menu option behaviour - Why is it inconsistent between C# and VB projects

When developing in a VS2005+ with C# project and I right click on a framework method/property/type and select ‘Go To Definition’, by default we get a new locked tab with code that has been generated from the framework, labelled appropriately [from metadata].
However when we do the same in a VB.NET project, you get taken to a new tab with the relevant Object Browser view.
This has always struck me as peculiar and was hoping there was a good reason behind it. IMO the object browser is nicer.
Is there a logical reason for the difference in default visual studio behaviour? If so, what is it?
It's a choice each team made based on what they believe their respective customers wanted to see. VB users have a historical attachment to the object browser and many VB features are integrated into it (Go To Def being one of them). C# made a switch in VS2005 to generate metadata on the fly for their version of GoTo def because they believed their customers would like the behavior better.
You can install Resharper for this.
It'll allow you to choose the default behavior when clicking the "go to definition".

VS2008 Navigate to class definition add-in

I am looking for a Visual Studio add-in that would analyze the text around the cursor position and navigate to the corresponding class definition.
For example I have this XML file that is currently open:
<object id="abc" type="MyProject.Foo.Bar, MyProject"/>
If I put the cursor somewhere between the double quotes on the type attribute the add-in should obtain the string "MyProject.Foo.Bar, MyProject" and search for all projects and project references in the current solution for the given type and if it finds one, it should navigate to the class definition (or metadata if the source code is not available in the current solution).
If such add-in doesn't exist I would greatly appreciate some pointers that could help me writing one.
Well you could use the 'Code Definition Window' that comes with the VS2008 IDE. When you place your cursor, the Code Def window dynamically updates with the source code for that type. Works with regular source files.. don't have the IDE at hand to verify with XAML/XML
Also you could 'Jump to Symbol' key combo but you would need CodeRush Express add in for that. Shift+Ctrl+Q. More details here.
Use the Alt+G command in Visual Assist.

Resources