Thursday, March 1, 2007

Helper macros for reloading the VS project and opening the project file for edit

Recently I had to reload quite often project files as I was changing custom imported targets. To minimize the amount of clicks I have created following macros:


    'Unloads the selected project and opens it for editing 
    Sub _EditSelectedProject()
        Dim proj As EnvDTE.Project
        If DTE.ActiveSolutionProjects.Length <> 1 Then
            MsgBox("Select one project within the Solution Explorer, then re-run this macro.")
            Exit Sub
        End If
        proj = DTE.ActiveSolutionProjects(0)
        DTE.ExecuteCommand("Project.UnloadProject")
        DTE.ExecuteCommand("OtherContextMenus.StubProject.EditProjectFile")
    End Sub
    'Subsequently executes unload and reload of the active project 
    Sub _ReloadSelectedProject()
        Dim proj As EnvDTE.Project
        If DTE.ActiveSolutionProjects.Length <> 1 Then
            MsgBox("Select one project within the Solution Explorer, then re-run this macro.")
            Exit Sub
        End If
        proj = DTE.ActiveSolutionProjects(0)
        
        DTE.ExecuteCommand("Project.ReloadProject")
    End Sub


Post a Comment