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.
- Place the caret on the column where you want to begin selection.
- Hold down the ALT key.
- 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.
- 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.