VS2008: Where is the Startup Project setting stored for a solution?

拜拜、爱过 提交于 2019-12-20 17:30:02

问题


When I right-click my solution in the Solution Explorer and choose Properties I get a dialog where I can select the Startup Project.

I sometimes select Current selection (If it is an experimental solution with lots of projects I jump between), but most often it is a Single startup project selected, which would usually be the main WinForms applications or or Console application.

My problem is that whenever I do a treeclean with the tfpt command (Team Foundation Power Tools 2008) this setting is forgotten. So when I try to run my solution the next time, it has defaulted to some random project and I get an error stating that I cannot run a class library or something like that. Which is obvious of course. But where is this setting stored? Why is it forgotten when I do the treeclean? The solution file is still there, right? Isn't solution properties stored there?


回答1:


Reference 1

Arian Kulp says:

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

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

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

Reference 2

Setting the StartUp Project

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

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

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




回答2:


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

I cannot confirm this but that would be my guess.

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




回答3:


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

slnStartupProject slnFilename projectName

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

The source is on github:

https://github.com/michaKFromParis/slnStartupProject

Forks and feedbacks are welcome.

Hope this helps!



来源:https://stackoverflow.com/questions/1238553/vs2008-where-is-the-startup-project-setting-stored-for-a-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!