我想要一个Visual Studio宏来删除给定XML文件中的所有注释。例如,鉴于此:
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Comment 1
-->
<config>
<!-- Comment 2 -->
<abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>
</config>
我想得到这个:
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>
</config>
我已经搜索了执行此操作的编辑器和VS宏,但找不到任何内容。
答案 0 :(得分:0)
我写了自己的:
Sub macro1()
DTE.ActiveDocument.Selection.StartOfDocument()
Do While True
DTE.ExecuteCommand("Edit.Find")
DTE.Find.FindWhat = "<!--"
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
DTE.Find.MatchCase = False
DTE.Find.MatchWholeWord = False
DTE.Find.Backwards = False
DTE.Find.MatchInHiddenText = False
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
DTE.Find.Action = vsFindAction.vsFindActionFind
If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
Exit Do
End If
DTE.Find.FindWhat = "-->"
If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
Throw New System.Exception("vsFindResultNotFound")
End If
DTE.ExecuteCommand("Edit.SelectToLastGoBack")
DTE.ActiveDocument.Selection.Delete()
DTE.ActiveDocument.Selection.DeleteLeft(4)
Loop
MsgBox("Done")
End Sub