CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: VB.NET

Visual Studio macro to toggle the MvcBuildViews value

709 Views
Copy Code Show/Hide Line Numbers
Sub ToggleMvcBuildViews()
    DTE.ExecuteCommand("Project.UnloadProject")
    DTE.ExecuteCommand("OtherContextMenus.StubProject.EditProjectFile")
 
    Dim wasSetToTrue As Boolean = SetMvcBuildView(True)
    Dim wasSetToFalse As Boolean
    If Not wasSetToTrue Then
        wasSetToFalse = SetMvcBuildView(False)
    End If
 
    If (wasSetToTrue Or wasSetToFalse) Then
        DTE.ActiveDocument.Save()
    End If
 
    DTE.ActiveDocument.Close()
    DTE.ExecuteCommand("Project.ReloadProject")
 
    Dim msgBoxTitle As String = "Toggle MvcBuildViews"
    If wasSetToTrue Then
        MsgBox("MvcBuildViews property was set to True", Title:=msgBoxTitle)
    ElseIf wasSetToFalse Then
        MsgBox("MvcBuildViews property was set to False", Title:=msgBoxTitle)
    Else
        MsgBox("Unexpected Error: Unable to toggle MvcBuildViews property", Title:=msgBoxTitle)
    End If
End Sub
 
Function SetMvcBuildView(ByVal value As Boolean) As Boolean
    DTE.ExecuteCommand("Edit.Replace")
 
    Dim findResult As vsFindResult
    findResult = DTE.Find.FindReplace(vsFindAction.vsFindActionReplaceAll, _
        FindWhat:="<MvcBuildViews>" & IIf(value, "false", "true").ToString() & "</MvcBuildViews>", _
        vsFindOptionsValue:=(vsFindOptions.vsFindOptionsFromStart Or vsFindOptions.vsFindOptionsMatchCase), _
        ReplaceWith:="<MvcBuildViews>" & IIf(value, "true", "false").ToString() & "</MvcBuildViews>", _
        Target:=vsFindTarget.vsFindTargetCurrentDocument, _
        ResultsLocation:=vsFindResultsLocation.vsFindResultsNone)
 
    SetMvcBuildView = True
    If (findResult = vsFindResult.vsFindResultNotFound) Then
        SetMvcBuildView = False
    End If
 
    ' close find/replace dialog
    DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()
End Function
by Al Gonzalez
  December 08, 2009 @ 9:31pm
Tags:
Description:
for more details http://algonzalez.tumblr.com/post/263944271/macro-to-toggle-mvcbuildviews-property

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate