As the title suggests I want to query all the Startup Projects set in a IVsSolution/IVsHierarchy
, also I would love to achieve that without the DTE
needed. Therefor DTE2.Solution.SolutionBuild.StartupProjects
isn't really a suitable option for me. I have look into the MSDN, but didn't find quite what I needed. I came across the IVsSolutionManager
with its get_StartupProject
method. Unfortunately it will only return a single startup project. Is this even doable with using the DTE
?
Asked
Active
Viewed 434 times
2

Twenty
- 5,234
- 4
- 32
- 67
-
If you can find all the project files from the SLN file, you can inspect the contents of the CSPROJ file and see if its outputting a EXE or DLL. EXEs can be startup projects. – JamesFaix Feb 05 '20 at 23:55
-
@JamesFaix I do not want to get the _theoretical_ startup projects. I am trying to get the actual ones. – Twenty Feb 05 '20 at 23:58
-
1There's only one startup project. – 3Dave Feb 06 '20 at 01:00
-
1@3Dave - not according to https://learn.microsoft.com/en-us/visualstudio/ide/how-to-set-multiple-startup-projects?view=vs-2019 – Vlad Feinstein Feb 06 '20 at 01:38
-
@VladFeinstein I stand corrected! Thanks for the link. – 3Dave Feb 06 '20 at 01:38
-
See if this helps: https://stackoverflow.com/questions/8817693/how-do-i-programmatically-find-out-the-action-of-each-startup-project-in-a-solut – Vlad Feinstein Feb 06 '20 at 01:44
-
@VladFeinstein `IVsPersistSolutionProps` seems to be very promising, I'll check it out later. Thanks for now! – Twenty Feb 06 '20 at 13:04
-
@VladFeinstein sadly I do not see anyway how I would get the startup projects by `IVsPersistSolutionProps`. Since I can't see a way on how I would get this interface. Actually I figured it out, but I am stuck on what to pass the [IVsPersistSolutionOpts.ReadUserOptions](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivspersistsolutionopts.readuseroptions?view=visualstudiosdk-2017#Microsoft_VisualStudio_Shell_Interop_IVsPersistSolutionOpts_ReadUserOptions_Microsoft_VisualStudio_OLE_Interop_IStream_System_String_) method. – Twenty Feb 07 '20 at 07:02
-
Sorry, I don't know. However, this guy appears to have a solution: https://stackoverflow.com/questions/37618573/visual-studio-get-the-startup-project-programmatically/37622771#37622771 – Vlad Feinstein Feb 10 '20 at 20:14
1 Answers
3
It appears, the EnvDTE.Solution.SolutionBuild.StartupProjects is the only way to do this. I did a walk through of the underlying VS IDE code base, and the startup projects are denoted by an internal flag on an internal C++ class tracking all the loaded projects. Unfortunately, neither that particular class or it's m_dwStartupOpt member are directly (or indirectly exposed.
So your best/only option here is to use that StartupProjects property.
Sincerely,

Ed Dore
- 2,013
- 1
- 10
- 8
-
Thanks for your time and answer. Anyhow it is really sad though, I really thought I could do it by using the [`VsPersistSolutionOpts.ReadUserOptions`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivspersistsolutionopts.readuseroptions?view=visualstudiosdk-2017#Microsoft_VisualStudio_Shell_Interop_IVsPersistSolutionOpts_ReadUserOptions_Microsoft_VisualStudio_OLE_Interop_IStream_System_String_) method. Unfortunately I do not know what I should pass for the `IStream` parameter. – Twenty Feb 10 '20 at 23:02
-
It might be possible, if the projects have persisted when you go to read the options. But the best/easiest solution is through that StartupProjects property. For what it's worth, it's utilized quite a bit in our own codebase. So there's really no need to "avoid" it. – Ed Dore Feb 11 '20 at 01:08
-
-
How do you get from StartUpProject to the actual Project's BuildOutputDirectory. Is there some way to get the StartUpProject's (assuming there is only 1) Project object? – Dominique Nov 07 '22 at 18:24