Sharing Classes between DSLs by using a DSL Library
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
In the Visual Studio Visualization and Modeling SDK, you can create an incomplete DSL Definition that you can import into another DSL. This lets you factor common parts of similar models.
Creating and using DSL Libraries
To create a DSL Library
Create a new DSL project, and choose the DSL Library solution template.
A single DSL project will be created with an empty model.
You can add domain classes, relationships, shapes and so on.
The elements in the library do not have to form a single embedding tree.
To define a relationship that importers can use, create two domain classes and create the relationship between them.
Consider setting the Inheritance Modifier of the domain classes to
Abstract
.You can add elements that you define in DSL Explorer, such as Connection Builders.
You can add customizations that require additional code, such as validation constraints.
Click Transform All Templates.
Build the project.
When you distribute the DSL for other people to use, you must provide both the compiled assembly (DLL) and the file
DslDefinition.dsl
. You can find the compiled assembly in a folder underDsl\bin\*
To import a DSL Library
In another DSL Definition, in DSL Explorer, right-click the root class of the DSL, and then click Add New DslLibrary Import.
In the Properties window, set the File Path of the library. You can use either a relative or an absolute path.
The imported library appears in DSL Explorer, in read-only mode.
You can use the imported classes as base classes. Create a domain class in the importing DSL, and in the Properties window, set Base Class to an imported class.
Click Transform All Templates.
Add to the DSL project a reference to the assembly (DLL) that was built by the DSL Library project.
Build the solution.
A DSL Library can import other libraries. When you import a library, its imports also automatically appear in DSL Explorer.
See also
Note
The Text Template Transformation component is automatically installed as part of the Visual Studio extension development workload. You can also install it from the Individual components tab of Visual Studio Installer, under the SDKs, libraries, and frameworks category. Install the Modeling SDK component from the Individual components tab.