VB.NET Tips / Tricks / Examples and Help

VB.NET How to make 'Show All Files' the default when creating new VB projects in Visual Studio

This article focuses on Visual Studio 2008 and Visual Basic 9, but it can be applied to other versions, I just have not tested these other versions with the steps outlined below. Feedback is welcome.

Show All Files is a useful little button in the Visual Studio solution explorer to give us a full view of the directory structure our project files are sitting in. When it is off, we only see the files that are explicitly included in the project, but when it is on, we see everything. This makes it very easy to explicitly opt a file into the project without doing an add -> existing item -> find existing item in directory structure and add to project.

The default when creating a new Visual Basic application in Visual Studio is to not show all files, and unfortunatly there is no setting you can adjust to change that. The good news is, it only takes a little bit of digging to figure out how to change a few things around, and get the functionality you want.

This example will use the Windows Forms template in Visual Studio. We are going to modify it, so that when you create a new Windows Forms project, it will default to show all files in the solution explorer. Of course the button in the solution explorer to toggle the feature will still work as it always did.

So lets get down to business here. The first thing we need to do, is go the directory where Visual Studio keeps its templates for VB Windows projects. The default directory if you installed to your C drive to the default path is

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\VisualBasic\Windows\1033

Navigating here should give you a list of folders that all end in ".zip". Yes these are folders not zip files, they correspond with the backup templates which are stored in zip files in another directory.

Open up the WindowsApplication.zip folder and you will see a list of files here. Most are the files that get added when you create this type of project, and there is also a vstemplate file, which has the specific details about how this template should be put together when a new project is created from it.

There are actually only 2 modifications you need to make here. If you want, you could make a backup of this folder before proceeding, however, as I mentioned above, there are backup zip files of the templates, located at:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\VisualBasic\Windows\1033

The 2 modifications we need to make to the template are

  • We need to add a .user file to this template. The .user file is the actual file that contains the ShowAllFiles setting.
  • We also need to modify the vstemplate file to indicate that the .user file should be made as part of the project, and that it should be renamed along with whatever the user names the project.

Right now you should be in the folder

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\VisualBasic\Windows\1033\WindowsApplication.zip

looking at the 12 files that make up the template. Create a new text file in this directory, and name it windowsapplication.vbproj.user

Open the file in a text editor, and add the following

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Save the file, and close it. The next step is to open the windowsapplication.vstemplate file in a text editor. You will see it is also just some XML settings.

Under the TemplateContent node we find a project node, which in turn contains ProjectItem nodes. We need to add a line here, so that the .user file we created will be included when we use this template.

Add the following node at the end of the ProjectItem nodes

<ProjectItem ReplaceParameters="true"  TargetFileName="$safeprojectname$.vbproj.user">windowsapplication.vbproj.user</ProjectItem>

This tells Visual Studio to copy the windowsapplication.vbproj.user file that we created when the template is used. The $safeprojectname$ variable ensures the file is renamed properly since the project name is determined when the project is being created. This file needs to match the name of the project to work correctly.

After you save this file, you are all done. You can open a new instance of Visual Studio and create a new Visual Basic Windows Forms application. You will see that Show All Files is now on by default for this template.

As you can see, templates can be very useful to add more functionality where Visual Studio does not give you an explicit option.

Posted Feb 02 2009, 08:45 AM by Matthew Kleinwaks

© 2014 - ZerosAndTheOne.com - Hosting by Orcsweb (http://www.orcsweb.com/)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems