Visual Studio Go to Definition - visual-studio

Go To definition in Visual studio 2005 works only for files that are in my project. It never works for files that are included in external libraries like mfc. When I say Go To Definition for mfc function it always shows me the header file . Is this expected behavior?
And also how does this whole thing Go To Definition work?
Thanks

I'd make the small investment required in Visual Assist. Besides all the great features it offers, it has the Alt+G command which works way better than the Visual Studio go to definition :)

For the MFC source files (at least the Feature Pack ones) I learned to find out what folder are they in (usually at C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc) and add that folder to the Find in Files dialog.
It's not as direct as Go to Definition, and you may have to browse among the find results, but it works...
Note: I second #flippy's answer of Visual Assist, it's really great.

External libraries are references to their compiled DLLs rather than the source when referencing your own projects.
The idea is that you don't need any more than the interface to external classes, but, if you would like to see the internals of DLLs you can use a tool such as Reflector.

Yes only the interfaces for MFC will be given in header file.Unless it is implemented with Template you will not be able to access the actual definition.The dlls have implementation for those interfaces.

Well if you think about it logically, as far as visual studio knows the only definition of the MFC object that is available is the definition it sees in the associated MFC header file, so unless you actually have the entire source for MFC it won't be able to look anywhere else.
The way that intellisense/go to definition works is via a file that is created when you compile the application. It stores a mapping between variables/functions and where they are declared (or could potentially be declared, in polymorphic situations), and when you right click to say "go to definition" it references that file.

Yes this is the expected behavior. Only the declarations (header files) of the MFC code are available on your box and hence that is the only location that it can take you to.
What are you expecting it to show?

Related

visual studio 2010 control library references

I wrote a control library using visual studio 2010, I'll call it MyLibrary. MyLibrary references another control library I have that we'll call AnotherLibrary. I also have a clean virtual machine (CVM) and I've added AnotherLibrary to the GAC on the CVM. Using the CVM, I create a new WinForms project, add MyLibrary.dll to the toolbox, and drop one of the controls onto the form. Visual Studio will add MyLibrary.dll AND AnotherLibrary.dll to the references, even though AnotherLibrary.dll is in the GAC (and isn't needed). I can remove AnotherLibrary.dll from the references and everything is fine.
Is there a way to prevent visual studio from adding AnotherLibrary.dll in this scenario?
Edit: I've given this some thought and I have an example. When you add a TabControl to a parent control in the designer, visual studio won't add System.Design to the references, even though the TabControl depends on it. So, surely there is a way to do this?
You still need the reference. Just like you need the reference to, say, System.dll which is also in the GAC. You just don't need the copy of the assembly in your bin\Debug directory. That you happened to not break the compiler by removing the reference is possible, especially since is this is an indirectly used assembly. But some odds that you'll eventually run out of luck.
In general you really want to avoid using the GAC on your dev machine. Because you care about specific versions of an assembly when you, say, create a bug fix. You get those specific versions from source control, not the GAC.
Doesn't it make sense that it would automatically include all dependencies? It cannot assume that AnotherLibrary is in the GAC on every machine you might want to deploy your code on. Of course as you mentioned you can manually remove it....

Code file templates in Visual Studio 2010

Xcode has a feature where each type of file has a template that is filled out when that type of file is created. By default, those files are located at /Developer/Library/Xcode/Templates/File Templates.
These files are used to give whatever default code you want, such as a common file header, even including things like the copyright year. I've gotten quite used to the functionality in Xcode, but I find myself missing it in Visual Studio. With VS I have to manually copy-paste the header and modify it myself for each file. Is there a way to get Visual Studio to automatically populate files (such as cpp's or .h's) with code?
EDIT: I'm trying to do this with C++.
Yes, you can use templates with macros etc in Visual Studio as well. MSDN has an article on it, and there are various blog posts on the topic too. I know they work for C# and VB - I expect C++ works in the same sort of way, but you'll need to check of course. (Apologies if this isn't the case.)
Unfortunately last time I looked it required expanding and then compressing zip files in a way that seemed a little unnecessary, but it should be doable.

What type of extension for VS (and how) to make, to generate C# or C++ code from some text [more so a model]?

I am new to Visual Studio Extensibility and want to make an addin/extension which shall do the following:
It should read all the files with a specific file extension (assume "*.ump").
It should process the text/code/whatever in the files.
It should create new Class/Code file with some code in it. [The code will be produced in step 2, just need to know how to do it?]
Yet, I have been racking my brains through extensibility, saw the single file generators .... and addins which go through ProjectItems and can detect the file extension,
BUT I HAVE NOT BEEN ABLE TO FIND a complete tutorial, guide or explanation as to how or what to do!!
Please help...
You don't want to read all files with a specific file extension in Visual C++ project nor standard Visual C# project. You may do that with hand-made MSBuild project (included in the solution).
In Visual C++ projects, there is a way to define custom tools. They are run as separate processes, so you can implement them in anything you want. Studio will ask you whether you want to define a tool (they are defined in special xml files; studio has dialog for editing them) when you add a file with extension unknown to it. In Visual C# projects, just manually write a MSBuild tasks and insert them into the project.
Do whatever you want. IIRC the generated files will have to be included in the project though. Well, for MSBuild, just tweak the project to your heart's desire, but in Visual C++ they have to.
You can combine MSBuild (csproj,vbproj) and VisualC++ projects in a single solution, so I recommend using separate.
If you ever find out you need to compile for different target where you can't use Visual Studio, you'll be glad that you have stand-alone tool you were just calling from Studio and not something that embeds in it.

Visual Studio 2010 - Add Reference Tabs will only give me projects. No Browse Allowed?

My problem seems pretty simple. I have a Solution with multiple projects and basically I am trying to do some mixing with C++, C# and CLI. My problem is that I need to add references from my c++ project. When the "Add Reference" dialog comes up, I only get tab for "Projects".
I know that usually you get multiple tabs for adding different reference types. What I am interested in is the "Browse" dialog. I need this to add a reference to a dll that is prebuilt. I am targeting .Net 4.0.
It seems like there is a project property that can be set to limit this but I'm not sure. MSDN seems to mention something along the lines that if you have multiple projects in a solution and they target different versions of the .Net framework, the list of possibilities may be limited.
In "How to: Add or Remove References in Visual Studio" MSDN mentions: "The number of tabs available at the top of the Add Reference dialog box can vary, depending on the type of project open and the resources it is using. C++ native projects contain only a Projects tab."
It doesn't really mention what these are specifically so maybe its just a broad subject. Anyways, I have stripped down the solution to only my C++ project and I can build successfully. However, I can only add References to other projects.
Apparently, setting the CLR option on the project is what opens up the list to include more options. I only wanted to enable it on one source file, but I guess Visual Studio will not add reference capabilities unless you turn it on for the whole project.
Therefore, my solution was to enable it for the whole project, add the reference, and then remove the option on the project. Basically a dirty trick but just in case people run into the same issue, that is what worked for me.
Erik

Watch for addition of a referenced library to a project (Visual Studio 2008 plug-in)

I am hoping someone can help me with this. What I have been looking around for but can't seem to find is if there is someway to add an event, or anything else that will allow a visual studio plug-in to watch for an external reference to be added to a currently open solution / project?
Or even better yet would anyone happen to know of an add-in that automatically adds all controls from a referenced dll into the visual studio toolbox?
Thanks.
Not exactly what you asked, but I've written a Visual Studio 2008 Integration Package, and if I recall correctly I could override the "add reference" method, as well as inherit the "reference node" and thus change its behavior, for example its constructor.
This functionality might be missing from an add-in (which is more limited than an integration package), so you might consider writing a package instead.
I have written a macro that will change a file reference to a project reference if you add the project to the solution (and vice versa), but I don't think that's what you want?

Resources