Visual Studio macro to select the startup project
In MSVC several operations (such as Menu: Build: Build ) are context sensitive to the currently selected Solution Project. However, that Project often changes if you've been navigating Solution Explorer.
I'd like to write a macro that f开发者_如何转开发ind the project specified as the "startup project", and the selects it to make it active. I haven't found the appropriate DTE calls though.
My primary goal was to build the startup project, which I have found a solution to:
Public Sub BuildStartupProject()
Dim sb As SolutionBuild = DTE.Solution.SolutionBuild
Dim projName As String = sb.StartupProjects(0)
DTE.ExecuteCommand("View.Output")
sb.BuildProject(sb.ActiveConfiguration.Name, projName, False)
End Sub
From the Chromium project wiki.
Here is somthing that should get you started, I have not verified if it will work when projects are nested inside a folder.
Sub SetStartupProjectasActive()
Dim solutionName As String = DTE.Solution.Properties.Item("Name").Value
Dim startupProject As String = DTE.Solution.Properties.Item("StartupProject").Value
Dim fullItemName As String = String.Format("{0}\{1}", solutionName, startupProject)
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
DTE.ActiveWindow.Object.GetItem(fullItemName).Select(vsUISelectionType.vsUISelectionTypeSelect)
End Sub
精彩评论