Walkthrough: Creating a Domain-Specific Language Solution
This walkthrough teaches how to create a domain model, a designer, and an artifact generator to build a domain-specific language that is based on a family tree. Related walkthroughs teach how to customize the designer and add validation to it.
Before you can start this walkthrough, you must complete these tasks:
Install Visual Studio 2008.
For a list of the Visual Studio editions that support Domain-Specific Language Tools, see Supported Visual Studio Editions for Domain-Specific Language Tools.
Install Visual Studio 2008 SDK.
Creating a Domain-Specific Language
Use the Domain-Specific Language Designer Wizard to create an initial domain-specific language for family trees.
To create a domain-specific language solution
On the File menu, point to New, and then click Project.
The New Project dialog box appears.
Under Project types, expand the Other Project Types node, and click Extensibility.
Under Templates, click Domain-Specific Language Designer.
Do not click the Domain Specific Language Setup template.
In the Name box, type FamilyTree as the name for the solution. Click OK.
The Domain-Specific Language Designer Wizard appears.
On the Select Domain-Specific Language Options page, select Minimal Language.
When you select a solution template, the wizard displays a description. For more information about solution templates, see Choosing a Domain-Specific Language Solution Template.
In the What do you want to name your domain-specific language box, the name that you specified for the solution (FamilyTree) appears by default. For this walkthrough, just leave it as is. Click Next.
The name that you type must be a valid Visual C# identifier because the system uses it to generate code.
On the Define New Model File Type page, in the What extension should model files use? box, type ftree. Click Next.
You can select Unregister domain-specific language tools that currently handle this extension if you want to disassociate a file name extension from a previously created domain-specific language and register the file name extension with this new domain-specific language. Domain-specific languages that are currently registered to the file name extension appear in the list. By default, Unregister domain-specific language tools that currently handle this extension is selected. We recommend that you leave the option selected or specify a different file name extension so that you can avoid registration problems.
The list under Other tools and applications registered to handle this extension shows conflicts with other file types on the local computer only. Also consider potential conflicts with registered file types on other computers, such as those of the language users.
You can change the file name extension that is associated with the domain-specific language after you complete the wizard.
On the Specify Product Details page, in the What is the name of the product that the new domain-specific language belongs to? box, type FamilyTree.
In the What is the name of the company that the product belongs to? box, type Fabrikam or your company name.
The names that you type on this page are automatically composed to create the namespace that is shown at the bottom of the page. The namespace should comply with the typical namespace rules.
Verify that the namespace is valid, and then click Next.
On the Select Strong Name Signing Method page, click Next to accept the default settings.
On the Review Details of the Domain-Specific Language Solution page, review the settings that you have specified.
If changes are required, click Previous to make corrections.
When you are satisfied with the settings, click Finish.
The wizard creates a solution named FamilyTree that is based on the Minimal Language solution template and the information that you supplied in the wizard. The solution has two projects, which are named Dsl and DslPackage.
When you create a project, the wizard automatically generates default text templates. When you generate a text template, a message alerts you not to run text templates from untrusted sources. You can set this message not to appear again.
The solution that you create by following this walkthrough has the name and language file name extension that are required to define a minimal language.
In Walkthrough: Customizing the Domain-Specific Language Definition, you can continue to define the domain-specific language for a family tree. As you follow the steps, you can learn about how to use the domain model designer and the notation that is used to define domain-specific languages. As far as it is defined in this walkthrough, the domain-specific language will let inconsistencies occur, for example, setting the birth date of a child to a date before the birth date of a parent. Walkthrough: Adding Validation to a Domain Model shows how to add validation to check for this mistake and inform users about it. The validation identifies the problem by comparing birth dates.
Rewrote and refactored project.
Content bug fix.