views:

1684

answers:

6

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?

+1  A: 

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
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
+1  A: 

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

http://stackoverflow.com/questions/31163/forcing-the-solution-explorer-to-select-the-file-in-the-editor-in-visual-studio#46193

Owen
+5  A: 

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
You surely meant "drastically decrease". :)
Kyralessa
Hah! Thanks Kyralessa! Fixed.
David Mohundro
+4  A: 

I love debugging with the Multiple startup projects option

Gulzar
+2  A: 

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.

Mario
And how you create the alias for subsequent open in VS?
Jhonny D. Cano -Leftware-
I didn't fully understand your question, but I hope my edit answers your question. VS remembers the alias until you explicitly remove it.
Mario
You can also use the search box in the toolbar to open files by typing ">of filename" (it autocompletes but has the same problem mentioned above).
Jersey Dude
Yup, I used that for a while too. Now, however, I just use ReSharper ;)
Mario
+9  A: 

First rule of working with Visual Studio:

Rinat Abdullin