I derived a small macro script from Visual Studio Macro to Format all Files in a Solution but unfortunately it doesn't work with xml, xaml, config etc. All ProjectItem
that are xml-based normally throw an exception (command not available) when they were opened in their primary view 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'
Results in:
System.Runtime.InteropServices.COMException (0x80004005): Command "Edit.FormatDocument" is not available.
at EnvDTE.DTEClass.ExecuteCommand(String CommandName, String CommandArgs)
When opening them as text with vsViewKindTextView
they stay as they are, although the Edit.FormatDocument
could be executed.
Is there another command that must be used for xml files? Is there something wrong with the code?