31

Is it possible to open a project in Visual Studio 2008 without opening all the files that were previously opened last time I had the project open. I have a habit of keeping many files open as I am working on them, so next time I open the project, it (very slowly) loads up a bunch of files into the editor that I may not even need open. I have searched through the settings and cannot find anything to stop this behavior.

mpal
  • 439
  • 1
  • 6
  • 8

9 Answers9

27

Simply delete the .suo file. It contains the list of open files.

Biri
  • 7,101
  • 7
  • 38
  • 52
  • 1
    it looks like in vs 2017 the suo is not the one along side your solution file but rather in a special .vs folder at the root. deleting this new one fixed it for me, thanks! – SelAromDotNet Jun 28 '17 at 15:32
26

A bit of research turns up the fact that you can do it with a macro:

  • Create a new macro (or use an existing one). You should see a module called EnvironmentEvents in Macro Explorer. (For details, see here.)
  • Open the EnvironmentEvents module.
  • Put in this code:

    Public Sub CloseDocsOnExit() Handles SolutionEvents.BeforeClosing
        DTE.ExecuteCommand("Window.CloseAllDocuments")
    End Sub
    
  • Save and Build the macro.
  • Open a whole bunch of documents in your solution, then close Visual Studio.
  • Yay! No more open documents!
  • (Note: Despite that it says SolutionEvents, it also works if you're working on a project that doesn't have a solution.)
Ryan Lundy
  • 204,559
  • 37
  • 180
  • 211
  • This worked for me also, thanks! The command in Visual Studio 2005, though, is: DTE.Documents.CloseAll(vsSaveChanges.vsSaveChangesPrompt) – John Sep 06 '11 at 14:14
  • +1 Worth mentioning that when you open a project without a solution, VS will create a temporary solution, hence the macro will work as expected – galaktor Feb 10 '12 at 14:00
5

I never realized how much that annoyed me as well! I haven't been able to find a setting, but in Options > Environment > Keyboard you can bind a shortcut to Window.CloseAllDocuments. ALT+X was unbound for me so I just used that. I'm interested if there's some hidden setting to automatically do this on solution exit though (or load).

travis
  • 35,751
  • 21
  • 71
  • 94
3

Try the following:

  1. Close the program after closing all files.
  2. Make a copy of [whatever].suo
  3. Open the solution again, open some files, and exit.
  4. Copy (don't move) the old .suo file over the one that was just generated.
  5. Make the .suo file read only.

If you have a repository you might want to check that file in.

I suggest this because I was having the reverse problem, where it wasn't opening my old files automatically, and the cause was a .suo file that had been checked into the repository and was (for some reason) not being overwritten by Studio. The file wasn't even write protected.

3

Edit: Totally read the question wrong at first - ignore my first (now gone) answer. :)

I changed the keyboard mapping for CTRL-SHIFT-C from bringing up the Class View to closing all document windows - something I use several orders of magnitude more often - and then I just clear my workspace before closing a solution.

Greg Hurlman
  • 17,666
  • 6
  • 54
  • 86
2

I was hoping for something a little more automatic. VS will create a new .suo file every time the project is saved. So I would have to delete that file every time I open the project. I also don't want to have to remember to close all the files before closing VS.

Other IDEs that I have used have similar functionality, but also make it rather simple to turn on/off.

Thanks for your help.

mpal
  • 439
  • 1
  • 6
  • 8
0

Or you can close all open document from the Window menu before closing VS.

Biri
  • 7,101
  • 7
  • 38
  • 52
0

In Visual Studio 6.0 (VC++), the procedure is slightly different.

Delete the .ncb file (located normally in the same place as your .dsp or .dsw files).

sam
  • 1,116
  • 2
  • 14
  • 19
-1

The only way works for me is : change the project location and again reopen the solutions form there. :)

gal
  • 1