是否有宏/扩展将Visual Studio中的所有Web项目设置为“不要打开页面”?

时间:2011-11-25 23:35:47

标签: asp.net visual-studio visual-studio-2010 debugging visual-studio-debugging

偶尔,我正在调试我们的几个后端Web服务中出现的问题,我将它们全部设置为启动项目;当我点击F5时,他们都会在我当时设置为默认值的任何浏览器中启动新标签 - 能够点击按钮并将所有Project > Properties > Web > Start Action设置设置为“不要打开一个页面。”任何人都知道可以帮助我的宏或扩展吗?

1 个答案:

答案 0 :(得分:3)

我为您编写了大部分解决方案,但我不确定如何检查Project是否是ASP.NET项目。一种方法是检查Project.ExtenderNames是否包含字符串“WebApplication”,但我不确定这是否是最佳解决方案。

Sub ChangeAllWebProjectsStartActionToDontStartWebPage()
    Dim project As EnvDTE.Project
    If DTE.Solution.IsOpen Then
        For Each project In DTE.Solution.Projects
            NavProj(project)
        Next
    End If
End Sub

Sub NavProj(ByVal project As Project)
    Dim outputPathProperty As EnvDTE.Property
    Dim outputPath As String

    If Not (project.ConfigurationManager Is Nothing) Then
        ' It's a project!
        Dim extenderNames As String()
        extenderNames = project.ExtenderNames
        If (Array.IndexOf(extenderNames, "WebApplication") >= 0) Then
            project.Properties.Item("WebApplication.DebugStartAction").Value = 4 ' WebStartAction.NoStartPage
        End If
    Else
        NavProjItems(project.ProjectItems)
    End If
End Sub

Sub NavProjItems(ByVal projItems As ProjectItems)
    Dim projectItem As EnvDTE.ProjectItem

    If Not (projItems Is Nothing) Then
        For Each projectItem In projItems
            If Not (projectItem.SubProject Is Nothing) Then
                ' Recurse, can be an Enterprise project in 
                ' Visual Studio .NET 2002/2003 or a solution folder in VS 2005+
                NavProj(projectItem.SubProject)
            End If
        Next
    End If
End Sub

这基于WebStartAction,定义为:

    enum WebStartAction
    {
        CurrentPage = 0,
        SpecificPage = 1,
        Program = 2,
        URL = 3,
        NoStartPage = 4
    }