【发布时间】:2011-05-19 17:25:12
【问题描述】:
我从 Visual Studio Macro to Format all Files in a Solution 派生了一个小宏脚本,但不幸的是它不适用于 xml、xaml、config 等。所有基于 xml 的 ProjectItem 通常在打开时抛出异常(命令不可用)在他们的主要观点vsViewKindPrimary:
Dim projectItem As ProjectItem ' actually this is a parameter of a sub'
Dim window As Window = projectItem.Open(Constants.vsViewKindPrimary)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("Edit.FormatDocument")
window.Close(vsSaveChanges.vsSaveChangesYes) ' actually this is part of a finally block'
结果:
System.Runtime.InteropServices.COMException (0x80004005): Command "Edit.FormatDocument" is not available.
at EnvDTE.DTEClass.ExecuteCommand(String CommandName, String CommandArgs)
当使用vsViewKindTextView 作为文本打开它们时,它们保持原样,尽管Edit.FormatDocument 可以被执行。
还有其他必须用于 xml 文件的命令吗?代码有问题吗?
【问题讨论】:
-
请添加任何德语消息的英文翻译,因为 SO 主要是英文问题和答案。谢谢
标签: xml visual-studio-2008 formatting visual-studio-macros envdte