21

After answering on this question I thought it would be nice to collect some tips & tricks for working with MSVS solutions and projects.

Here is my list:

  • How to avoid saving new projects automatically to reduce garbage in file system.

    Uncheck Tools->Options->Projects and Solutions->Save new projects when created

  • How to add common file to multiple projects without copying it to project’s directory.

    Right click on a project, select Add->Existing Item->Add as link (press on small arrow on Add button)

  • How to add project to solution without including it in the build process

    Right click on solution, select Add->New solution folder.
    Right click on created folder, select Add->Add existing project

  • How to edit project file from Visual Studio?

    Right click on project and select Unload Project, right click on unloaded project and select Edit. Or install Power Commands and select Edit Project File

  • How to group files in the project tree (like auto-generated files for WinForms controls)

    Open project file for editing.

   Change
<Compile Include="MainFile.cs" />
<Compile Include="SecondaryFile.cs" />

To

<Compile Include="SecondaryFile.cs ">
    <DependentUpon> MainFile.cs </DependentUpon>
</Compile>

Do you have anything else to add?

Community
  • 1
  • 1
aku
  • 122,288
  • 32
  • 173
  • 203
  • 2
    The "Add as link" thing, it doesn't work for web projects being developed locally as the file is not copied until web project is published. The file cannot be found physically on disk by the WebDev server, any solution? – John Leidegren Feb 13 '09 at 13:19
  • 1
    And again, the most constructive questions getting closed as "not constructive"... – TT_ stands with Russia Nov 14 '13 at 23:16

6 Answers6

17

First rule of working with Visual Studio:

Rinat Abdullin
  • 23,036
  • 8
  • 57
  • 80
5

I'm a huge fan of using msbuild to build my solutions with the /m option so that it builds using multiple cores. It can drastically decrease your build time.

Scott Hanselman posted on how to add it to your tools list at http://www.hanselman.com/blog/HackParallelMSBuildsFromWithinTheVisualStudioIDE.aspx.

I usually just run 'msbuild /m' from the command prompt or PowerShell, though.

Another tip that is sometimes useful is taking advantage of the pre- and post-build events to add additional logic before or after a build. To see these, go to the Properties for a Project, click on the Compile tab, and then choose "Build Events..."

David Mohundro
  • 11,922
  • 5
  • 40
  • 44
4

I love debugging with the Multiple startup projects option

Gulzar Nazim
  • 51,744
  • 26
  • 128
  • 170
2

Using the command window to quickly open files in your solution:

  1. Bring up the Command Window (CTRL-ALT-A)
  2. Type open <filename>

I create an alias for open by executing the following at the Command Window: alias o open. Visual Studio will remember the alias from then on, so I only ever need to type o <filename>.

It even searches database projects unlike some third-party plugins!

Unfortunately, there is a bug in the filename completion when searching for nested files. A simple workaround is to type the beginning of the filename, hit the ESC key and then type the rest of the name. To search for login.aspx.cs, type login.aspx, hit ESCP and then type .cs.

AEM
  • 1,354
  • 8
  • 20
  • 30
Mario
  • 2,229
  • 2
  • 21
  • 21
2

I like changing the default location that new projects are saved to.

Tools->Options (Select Projects and Solutions tab)

This "tab" has all sorts of goodness. Not just the ability to change the default locations and avoid saving new projects automatically but other nice things as well. For example:

Track Active Item - Selects the file in the solution explorer when you change windows.

Show Output window when build starts - Toggle to show or not. I like it on, your mileage will vary.

Craig
  • 11,614
  • 13
  • 44
  • 62
  • Track Active Item in Solution Explorer is one of the features I regret are not on by default. So many people have gasped in wonder as I check the box and show them what it does. – Omer van Kloeten Sep 10 '08 at 14:19
1

I have a tip regarding the "Track Active Item" option mentioned above, for when working with big projects. It's posted here:

Forcing the Solution Explorer to select the file in the editor in visual studio 2005

Community
  • 1
  • 1
Owen
  • 7,494
  • 10
  • 42
  • 52