May 2010 - Posts

FAQ: Rectangular selection in Visual Studio

Q: I need to delete some code from several lines and the code is well formatted.  Can I use some sort of regular expression to replace the code?

A: You could but this might be overkill.  VS has supported rectangular selection for a while.  With rectangular selection you can select a block of code and then select that same block on several consecutive lines and then delete the selected code. 

Do the following to use rectangular selection.

  1. Place the caret on the column where you want to begin selection.
  2. Hold down the ALT key.
  3. Drag the mouse to select the region you want to select.  If you cross lines then the same columns are selected on all the lines.
  4. Release the ALT key and then press DEL to delete the columns from each line.

Starting with VS2010 some new capabilites were added.  They are discussed here.  My personal favorite is the ability to replace the same block of code on all lines (such as renaming private to public). 

To do that just select the region that you want to replace and then begin typing the replacement text.

FAQ: Temporary Projects

Q: I create a lot of test projects and I am getting tired of cleaning up the temporary projects directory and clearing out the recent projects menu.  Is there some way to get VS to do this for me?

A: Yes there is.  Under Tools\Options -> Projects and Solutions there is an option called Save new projects when created.  Unchecking this option will allow you to create (most) new projects without saving them.  It will still end up in your temporary projects folder but it will be automatically deleted when you close the project unless you chose to save it.  Furthermore it will not be added to the MRU project list.

 There are some restrictions to this option.  Firstly not all project types support it.  C++ does not while C# and VB do.  Secondly, you cannot create multiple projects in a single solution without saving it first.  You also cannot do some project changes without first saving the project.  Avoid using the Save All button as this will prompt you to save the project.  However you can add files and compile and debug without saving.

FAQ: Toolbox is slow to populate

Q: Whenever I accidentally mouse over the Toolbox it locks up VS for a while.  What is going on?

A: This should only happen the first time you mouse over the Toolbox after starting VS.  VS is populating the window with the controls that are defined within your solution in addition to the pre-defined controls.  This can be a slow process.  To speed it up go to Tools\Options -> Windows Form Designer\General and set AutoToolboxPopulate to false.  This will tell VS not to scan your solution looking for controls to add to the toolbox.

 

FAQ: Adding a lot of files to a solution

Q: I need to add a lot of existing files and folders to a project but using Add Existing Item is slow.  Is there a faster way?


A: When you select a project in Solution Explorer you might have noticed the toolbar at the top of the window changing.  One of the option (in most projects) is Show All Files.  This option shows all files and folders under the project folder whether they are in the project or not.  Files/folders not in the project are shown grayed out.  If you right-click the files/folders (multiple selection is supported) you can right-click and select Include in Project to automatically add them to the project.  If you add a folder it will automatically include any children in the folder.  This is a great way to add a lot of items when they already reside in the project directory.

If the files do not already reside in the directory then you can drag the files from Windows Explorer to the project directory.  Unfortunately this does not work in all projects.  Also be careful about what actually happens when you drop the file.  For projects like C# that assume all files are in the project directory then a copy is performed.  However some project types may result in a link being created to the original file location.

FAQ: Access Denied when signing an assembly

Q: When I try to sign an assembly I get an access denied error.  What is going on?

A: By default you can not sign an assembly unless you have administrative privileges.  This is due to security set on the key(s) used for signing.  To enable your account for signing assembly you will need to modify the NTFS security on the folder %ALLUSERS%\Application Data\Microsoft\Crypto\RSA\MachineKeys to give your user account (or better yet a group in which your account is a member of) full control.  You will need read & execute, list and modify rights.  You can then sign assemblies without administrative privileges.

Web Sites vs Web Applications
(Originally published: 3 January 2009) One of the biggest confusions in the ASP.NET world is that of web project type. Visual Studio (VS) supports two web project types: web sites and web applications. Unfortunately, they are different enough that it...
Integrating GAC Assemblies with Visual Studio
Originally published: 19 February 2006 Updated: 20 May 2010 The question comes up all the time about how to get documentation and debugging support for GAC assemblies into Visual Studio (VS). This article will discuss the steps it takes to make this happen...
Configurations and Platforms in Visual Studio
(Originally published: 7 June 2008) Anyone who has worked with Microsoft Visual Studio (VS) knows about configurations but not many people, other than handheld developers, know about platforms. This article will discuss configurations and platforms as...
Using the FileSystemWatcher
(Originally published: 10 June 2007) The FileSystemWatcher (FSW) component available in .NET is being used more and more every day. Unfortunately FSW does not work quite the way you would expect. This article will discuss how to use the FSW in a .NET...
The Case of the Mysteriously Changing Font
A while back I wrote up a simple IP address control for WinForms. This control relied on the underlying IP Address common control from Windows. The goal was to provide the ability, in WinForms, to enter and validate an IP address without having to write...