[ACCEPTED]-Where is the Startup Project setting stored for a solution?-projects-and-solutions

Accepted answer
Score: 21

Reference 1

Arian Kulp says:

I was struggling with trying to figure out 36 why a certain solution of mine wasn’t starting 35 right. It was in VB with four projects. Upon 34 initial open it would set a certain project 33 with a DLL output as startup. If I set 32 the EXE as startup project, it was fine, but 31 when I distribute code I always clean it 30 by removing *.suo and *.user files, and 29 bin/obj folders. Upon opening the “cleaned” version, it would 28 always revert to the DLL project and fail 27 to F5 nicely. The fix turned out to be 26 simple, though I’m curious as to why I needed 25 to do this at all.

In the solution file, there 24 are a list of pseudo-XML “Project” entries. It turns 23 out that whatever is the first one ends 22 up as the Startup Project, unless it’s overridden 21 in the suo file. Argh. I just rearranged 20 the order in the file and it’s good.

I’m 19 guessing that C# is the same way but I didn’t 18 test it. I hope that this helps someone!

Reference 2

Setting the StartUp Project

Which 17 project is the "startup" project 16 only has any relevance for debugging, which 15 means it's user metadata from the point 14 of the solution and the projects. Regardless 13 of which project is the "startup" project, the 12 compiled code is the same.

Because of this, the 11 information is stored as a user setting 10 in the Solution User Options file (solution.suo) which 9 accompanies the Solution file (solution.sln). The 8 .suo file "Records all of the options 7 that you might associate with your solution 6 so that each time you open it, it includes 5 customizations that you have made" according 4 to MSDN.

The .suo file is a binary file. If you 3 want to read or change it programatically, you 2 have to use IVsPersistSolutionOpts.LoadUserOptions from the Microsoft.VisualStudio.Shell.Interop 1 namespace.

Score: 1

I suspect that this setting is saved as 6 part of the .suo file created whenever you 5 edit a solution file. This file contains 4 various user settings, such as breakpoints, watch 3 data etc.

I cannot confirm this but that 2 would be my guess.

Unfortunately its not 1 XML its a binary file and not easily edited.

Score: 0

I just wrote a little command line utility 7 for windows called slnStartupProject to solve this. It sets 6 the Startup Project automatically like this:

slnStartupProject slnFilename projectName

I 5 personally use it to set the project after 4 generating the solution with cmake that always 3 sets a dummy ALL_BUILD project as the first project 2 in the solution.

The source is on github:


Forks 1 and feedbacks are welcome.

Hope this helps!

More Related questions