How to keep several files in a tree in Visual Studio? - visual-studio

When you add (for example) WPF window to your project VS creates .xaml and .xaml.cs files. However they are not displayed in a flat list in VS Explorer, rather .xaml.cs is a child file (in terms of the tree) of .xaml file.
How to organize several "custom" files into such tree? For example I have Trainer.cs file and Trainer.Builder.cs file. I would like Builder to be displayed as a child of Trainer.cs file. How to do it?
Please note: I know about folder with files, but I don't want to use it, because in such case even the "main" file is hidden and I have to unfold folder to get it.
Update
While searching for difference between VS2008 and VS2010, I found out, that my entire question is a duplicate of SO question -- there you find how to fix a fix for VS2008 to work with VS2010 :-)
Visual Studio 2010 related file nesting

This can be done by editing the registry. A guide to doing this for Visual Studio 2008 can be found here: http://blog.dotnetwise.com/2009/09/visual-studio-2008-custom-nested-files.html
You can also do this through a Visual Studio Extension, but unless this is part of a larger project this is probably overkill. There is a guide to implementing this behavior here: http://pieterderycke.wordpress.com/2011/03/10/adding-support-for-nested-files-in-custom-visual-studio-project-types-with-mpf/

Related

Visual Studio 2010 Toolbox Is Empty

My toolbox is empty.
Obviously, I'm not the first. I read this question and this other question, but that didn't help.
I click here...
I get this window...
With instructions that say: "...Drag an item onto this text, to add it to the toolbox..."
Sounds good; from where do I get such items to drag?
The toolbox is empty because there is no project loaded.
The toolbox is populated with tools/controls according to the type of the current project. The controls are different for MFC than they are for ASP.NET, for example. If you haven't loaded any project, Visual Studio can't populate the toolbox.
Either open an existing project, or go to File -> New Project to create a new one.
Have you tried right-clicking on it and selecting the "Reset Toolbox" option? You can also try to manually add specific tools to it by using the "Choose Items..." option.
A common suggest is also to go into the Visual Studio 2010 Directory and delete all of the .tbd files within the following directory (Related) :
C:\Documents and Settings\Local Settings\Application Data\Microsoft\VisualStudio\10.0"
Although if neither of these options work, you will really want to consider possibly reinstalling / repairing Visual Studio.
Is your project running? I noticed that my toolbox is empty when I am debugging the project. Try stopping debugging.

How to reload a property sheet in Visual Studio 2010

Is there a way to reload a property sheet that was edited outside of Visual Studio? Visual Studio doesn't detected automatically that the file was modified (like it does with project files). The only way I've found so far is to close and reopen the whole solution (but that's no good way).
Only a partial solution perhaps for your (and my) needs, but I've found it helpful to touch the .sln file. This causes Visual Studio to wig out and ask if you want to reload all the projects. Select "Yes" and then you'll notice the properties have refreshed. I make sure that my scripts which update property files also touch any related solution file(s).
Also see Is there any way to get Visual Studio to reload all projects when the .proj files have changed?

Can't "go to declaration" in *.ashx files (Visual Studio 2008)

When I open *.ashx files in Visual Studio, I don't have the helpful "Go to Declaration" context menu when right-clicking on a function.
How can I restore this functionality (this is a new install)?
Thanks very much.
Click on the text you want to go to and key F12 if it's not showing up for you.
Much like Windows Operation Systems need to reboot when things start breaking down, Studio sometimes needs a restart if that doesn't work.
Obviously this doesn't get your menu item back, but it's a fix that you might prefer over selecting that from the right-click mouse menu.
This is a shot in the dark since I do not work with ASP-related stuff.
Short Answer
If your *.ashx files belong to a project, open the project first.
Longer Answer
Most of my work in Visual Studio 2008 is with C++ and C# code. If I open a .cpp file or .cs file in VS2008 independent of the project it belongs to, VS2008 doesn't give me the Go To Declaration context menu either. When I open files independent of the project they belong to, VS2008 (or any Visual Studio version for that matter) is little more than a glorified editor. To get the benefit of Go To Declaration and other features, e.g., Intellisense, I have to first open the project and then open the file from within VS2008.
Alternate Answer
If you are already doing this, you might try deleting the .suo file in your project directory and letting VS2008 re-create it.
Apology
Sorry if this was simply stating the obvious. I know I've been frustrated at times when I've opened a file outside the context of its project only to realize what I want to do requires me to open the project anyway. Someone new to Visual Studio might not realize the project is sometimes required.

Hidding source control files within Visual Studio's solution tree

We use Visual Studio 2008 and Surround SCM for source control. SCM drops files into each directory named ".MySCMServerInfo" which are user specific data files that shouldn't be checked into source control. They are similar to the .scc files dropped by Visual Source Safe. We also have several WAPs (Web Application Projects) that we develop. All these .MySCMServerInfo files show up in the solution tree and the Pending Checkins window when they should not. There has to be some way to force VS to ignore files of a given extension because it ignores .scc files. How do I get VS to ignore .MySCMServerInfo files within a WAP?
I have new information about this issue. Setting the hidden bit on .MySCMServerInfo file causes Surround SCM to loose track of the modification state for files. It starts thinking files are out-of-date when they are not, and it always attemps to get new versions.
Instead, set this registry key if you're using Visual Studio 2008:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Packages\
{8FF02D1A-C177-4ac8-A62F-88FC6EA65F57}\IgnorableFiles\.MySCMServerInfo]
Set this registry key if you're using Visual Studio 2005:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\
{8FF02D1A-C177-4ac8-A62F-88FC6EA65F57}\IgnorableFiles\.MySCMServerInfo]
These will tell Visual Studio to not display .MySCMServerInfo files within the Solution tree and the Pending Checkins view.
Using the file system hidden bit should work.
Late Answer but hopefully useful to others.
I began experiencing this problem when using Visual Studio 2015 with the new ASP.Net 5 Project templates. (I presume this is because the new templates automatically include everything in the folder rather than only showing the things that are listed in the project file).
Showing these files in the Solution explorer change be prevented by right clicking the file and selecting "Hide from Solution Explorer" but this didn't prevent SCM from including them in the Pending Check-ins Window.
The correct way to deal with this problem is:
Select the file(s) in Solution Explorer
Select the File > Source Control > Exclude from Source Control
Reference
NOTE: Right Click in the Solution Explorer DOESN'T have this option.

Automatically adding specified text at beginning of files in VS 2008

Is there a way to have Visual Studio 2008 automatically add heading information to files? For example, "Copyright 2008" or something along those lines. I've been digging through the options, but nothing seems to be jumping out at me.
I assume you'd like to modify the class file templates. They're in:
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033
More specific details here
I found a better solution than modifying the template file directly. This utility allows you to create and save header/footer templates and apply them to entire source trees.
C# Header Designer from MSDN Code Gallery

Resources