Programming with the UML API


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at Programming with the UML API.

The UML API of Visual Studio lets you write code to create, read, and update UML models and diagrams. To see which versions of Visual Studio support UML models, see Version support for architecture and modeling tools.

In addition to the API reference pages, the following topics describe the API.

TopicExample types and methods describedFeatures described
Navigate relationships with the UML APIUML elements and their properties and associations. For example, IElement and its descendants, including: IClass, IActivity, IUseCase, IComponent, IInteraction, IModel, IPackageIn Visual Studio, UML models conform to the UML specification version 2.1.2, which can be obtained at the UML Resource Page. Each type is an interface that has the same name as the UML type, prefixed with "I".
Create elements and relationships in UML modelsIPackage.CreateClass()

Each element type has methods for creating its children.
Display a UML model on diagramsIShape, IDiagram

Each element in a model can be represented as a shape on a diagram. In some cases, you can create new shapes for each object. You can move, resize, color, and collapse or expand these shapes.
Navigate the UML modelIModelStore

The Model Store stores the model.

The Diagram Context gives you access to the current diagram and store.
Link UML model updates by using transactionsILinkedUndoContextYou can link a series of changes into one transaction.
Define a menu command on a modeling diagramIMenuCommand


You can extend a diagram's functionality by defining commands invoked by double-clicking and by dragging onto the diagram.
Define validation constraints for UML modelsValidationContextYou can define validation rules that help you make sure that a model conforms to specified constraints.
Get UML model elements from IDataObjectIElement, IShapeWhen an element is dragged from UML Model Explorer or a UML diagram to another diagram or application, it is serialized as an IDataObject.
Edit UML sequence diagrams by using the UML APIIInteraction, ILifeline, IMessageCreating and updating an interaction diagram is slightly different from working with the other diagram types.
Extend layer diagramsILayer, ILayerDiagramYou can write code to create and edit layer diagrams, and also validate program code against them.

The UML modeling tools are built on Domain-Specific Language Tools. Each package and each diagram is represented by a Domain-Specific Language Tools model, and a collection of rules and other methods maintains consistency between them.

Types from that platform are visible in some of the assemblies that you reference in order to write UML extensions. Although you can make extensions to the UML tools by accessing the Domain-Specific Language Tools API, you should bear the following considerations in mind:

  • You might find that some apparently simple changes introduce inconsistencies and unexpected effects.

  • The implementation may change in the future, so that adaptations you make using the Domain-Specific Language Tools API might no longer work.

This table summarizes the assemblies that provide extensibility for the UML tools, and the namespaces that you are recommended to use.

AssemblyNamespacesProvides access to:
Microsoft.VisualStudio.Uml.Interfaces(All)The UML types.
Microsoft.VisualStudio.ArchitectureTools.ExtensibilityMicrosoft.VisualStudio.ArchitectureTools.Extensibility.UmlCreation methods
Microsoft.VisualStudio.ArchitectureTools.Extensibility.PresentationDiagrams and Shapes
Microsoft.VisualStudio.ArchitectureTools.ExtensibilityThe modeling project
Microsoft.VisualStudio.Modeling.Sdk.[version]Microsoft.VisualStudio.Modeling.ExtensionEnablementMenu command extension.

 Linked Undo transactions.
(other namespaces)Recommended only for advanced use.
Microsoft.VisualStudio.Modeling.Sdk.Diagrams.[version]Microsoft.VisualStudio.Modeling.Diagrams.ExtensionEnablementGesture handlers.
(other namespaces)Recommended only for advanced use.
Microsoft.VisualStudio.TeamFoundation.WorkItemTrackingMicrosoft.VisualStudio.TeamFoundation.WorkItemTrackingLinks to work items.
Microsoft.TeamFoundation.WorkItemTracking.ClientMicrosoft.TeamFoundation.WorkItemTracking.ClientWork items and their fields.
Microsoft.TeamFoundation.ClientMicrosoft.TeamFoundation.ClientWork items and their fields.
System.ComponentModel.CompositionSystem.ComponentModel.CompositionExport and Import for MEF components
System.LinqSystem.LinqEasy manipulation of collections, especially when dealing with relationships.

Extend UML models and diagrams
API Reference for UML Modeling Extensibility