Visual Studio Authoring Extensions - Visual Studio Features
XML editing
Visual Studio is optimized to provide language support in whatever language you’re currently working in, and that includes XML. When you start a new project in Visual Studio, you select one of the templates from the Management Pack group, and your project starts with the appropriate XML schema already loaded. As you’ll see in the section on IntelliSense, this allows you to use a number of assistive tools that already know the schema needed for management packs.
VSAE takes some of the work out of creating the management pack fragments. When you select one of the basic templates, you’re presented with skeleton XML for that element, with comments that provide some information about the parts of the code that you need to fill in yourself.
Advanced templates, instead of requiring you to edit the XML directly, allow you to edit the properties of the element you’re creating in the Properties window. Once you save the element, the XML for that element is generated for you automatically. You don’t ever need to look at the XML yourself, but if you want to, you can. In the Solution Explorer, underneath each template group, you’ll see the MP fragments that make up that group. Double-click the fragment you want to edit, and the code will open in the main editing window.
Organization
Because VSAE divides the various management pack elements into MP fragments, looking for a particular element becomes easier, based on the organization scheme you choose. Each basic or advanced template that you use creates a new management pack fragment or management pack template group. You’re then free to edit these fragments or create new ones, according to your organizational scheme. You can, for example, keep all your unit monitors in one fragment, or you can keep each unit monitor in a separate fragment, or you can divide them however you see fit. You don’t have to deal with large, hard-to-read XML files if you don’t want to.
Customizable windows
When you create or edit a simple template management pack item, the XML code appears in the main editing window, which allows you to use Visual Studio’s editing features, discussed later.
When you use an advanced template, instead of editing the XML directly, you edit the properties for the element in the Properties window, and the XML is generated for you when you save. If you stick with the default window configuration, it may seem a bit odd to be editing the element in a small window on the lower-right, while leaving the main window mostly blank. Fortunately, all the windows in Visual Studio can be moved, resized, or docked to another part of the interface. If you’re going to be spending a while editing properties, just drag the window out to the main area and enlarge it.
Find and Replace
At some point, most MP authors are faced with the task of renaming an element in multiple locations in a very large MP file. Depending on the XML editor you’re using, that can be anywhere from slightly annoying to dauntingly tedious. Because VSAE divides the management pack elements into multiple fragments within the project, you may think that a global find and replace action would be a nightmare. Fortunately, Visual Studio gives you the ability to search and replace across all the files in a given project. To open the Find and Replace dialog box, select Edit → Find and Replace → Quick Find, or press Ctrl+F.
From here, you can find instances of text in any of the files in this project. You can use the “Look in” drop-down to expand the search to the entire solution.
IntelliSense
One of the more useful features of the VSAE is IntelliSense support. IntelliSense dynamically determines the context where you’re typing, and suggests a list of appropriate elements for that point. For example, if you create a new blank management pack fragment element (the simplest available element), and inside that element you type an opening bracket (<), IntelliSense pops up a list of available elements that can be used at that spot. In this case, that’s all the main management pack elements, as you can see:
All you need to do is select the element you want, press Tab or Enter, and the element is entered for you, saving you from having to type it. When you type the closing bracket (>) for the element, the closing tag is automatically created as well:
IntelliSense tailors the suggestions it provides to the context where you’re typing. For example, if you’ve created a <ClassTypes> entity, the only valid child entity is a <ClassType> entity, so that’s all that IntelliSense displays (along with the standard comment and declaration entities):
IntelliSense will fill in properties of entities as well, if the entity is defined in the schema. In this case, if you’ve typed the opening tag for a ClassType and press the spacebar, IntelliSense provides a list of the possible properties for a ClassType:
As you add each property to the definition, it’s removed from the list, so you can’t enter a property twice by accident.
IntelliSense can even provide possible values for properties, if they're known. In some cases, however, IntelliSense doesn't trigger automatically. In that case, you need to press Ctrl + Space, or Ctrl + K + W (these are the default bindings) to trigger IntelliSense.
AutoCorrection
Visual Studio alerts you to errors in your code as you type it. This takes the form of underlining the code with wavy red or blue lines, as you may have seen in Microsoft Word or Microsoft Excel. For example, if you close a tag without including all the required attributes, a blue line appears under the entity type. If you hover the cursor over the type, a pop-up will tell you exactly what’s missing:
If you have a typo in your property declarations, the blue line also indicates that, because the property is undeclared, and Visual Studio doesn’t recognize it:
Of course, if you’re using IntelliSense to provide the attribute names for you, you’re much less likely to have a typo.
The red lines alert you to more basic errors, such as forgetting to close a tag:
That means, however, that as you type, you’ll frequently see red lines warning you about tags that aren’t closed, because you haven’t finished defining them yet. These will disappear as you add the appropriate code.
Additional Resources
[[Visual Studio Authoring Extensions for System Center 2012 - Operations Manager]]
[[Visual Studio Authoring Extensions - Simple Templates]]
[[Visual Studio Authoring Extensions - Advanced Templates]]
[[Visual Studio Authoring Extensions - Example Management Pack]]