How do you get server blocks <% %> to format well in Visual Studio?

后端 未结 2 971
滥情空心
滥情空心 2020-12-24 03:15

I\'m using ASP.NET MVC a lot recently which means using server blocks a bunch. Visual Studio does this strange thing when I type:

<% } %>
相关标签:
2条回答
  • 2020-12-24 03:17

    i think you format it by Ctrl + K, Ctrl + D

    0 讨论(0)
  • 2020-12-24 03:27

    Looking at the behavior. I don't know that you can override it just for the HTML editor. It is exhibiting the exact behavior that is defined in the C# editor preferences.

    I suppose you could modify the behavior for a closing brace in the C# editor preferences, but it would do fugly things to your .cs files.

    Edit:

    I got tired of trying to find other ways to do it. So I wrote this macro. Tested in VS 2k8. Not 2k5. You can see what it does. Also, sorry about the VB, but it was the default for the macro editor.

    Sub FixFormatCurrentFile()
    
        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        Dim fixed As String = "<% } %>"
        Dim regex As String = "\<\%:Wh*\}:Wh*\%\>"
    
        While selection.FindPattern(regex, vsFindOptions.vsFindOptionsRegularExpression)
            selection.ReplacePattern(regex, fixed, vsFindOptions.vsFindOptionsRegularExpression)
        End While
    End Sub
    
    0 讨论(0)
提交回复
热议问题