Walkthrough: Creating a Domain-Specific Language Solution
In this walkthrough, you create a domain model, a designer, and an artifact generator to build a domain-specific language that is based on a family tree. In subsequent walkthroughs, you can customize your designer and then add validation to it.
注意
When you install Domain-Specific Language Tools, you also install samples such as the FamilyTree sample on which this walkthrough is based. For more information, see Family Tree Sample.
Prerequisites
For this walkthrough, you must:
Install Visual Studio 2008.
注意
For a list of the Visual Studio 2008editions that Domain-Specific Language Tools supports, see Supported Visual Studio Editions for Domain-Specific Language Tools.
Install Visual Studio 2008 SDK.
Review the topic Family Tree Sample.
Creating a Domain-Specific Language
In this walkthrough, you use the Domain-Specific Language Designer Wizard to create the 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.
Important Note: Do not choose the Domain Specific Language Setup template.
In Name, type FamilyTree name for the solution, and click OK.
The Domain-Specific Language Designer Wizard appears.
On the Select Domain-Specific Language Options page, click Minimal Language.
When you click a solution template, the system displays a description. For more information about solution templates, see Choosing a Domain-Specific Language Solution Template.
注意
To switch between large and small icons in the list of solution templates, click the Large icons and Small icons buttons, which appear next to the list of solution templates.
In What do you want to name your domain-specific language, leave the name that you specified for the solution of FamilyTree, which appears by default, and then click Next.
注意
The name that you type must be a valid Visual C# identifier. The system will use it to generate code.
On the Define New Model File Type page, under What extension should model files use?, type ftree, and then click Next.
You can select the Unregister domain-specific language tools that currently handle this extension check box if you want to disassociate a file extension from a previous domain-specific language and register the file extension with the new domain-specific language. If any domain-specific languages were previously registered to the file extension, they appear in the list. The check box for unregistering the extension is the default selection. In general, you should leave the check box selected or specify a different file extension to avoid having more than one domain-specific language registered to the same file extension.
The list under Other tools and applications registered to handle this extension shows conflicts with other file types on the local computer only. You should recognize potential conflicts with registered file types on other computers, such as those of your language users.
注意
You can edit the extension that is associated with your domain-specific language after you finish using the wizard.
On the Specify Product Details page, under What is the name of the company that the product belongs to?, type Fabrikam or your company name.
The names that are given on this page are automatically composed to create the namespace shown at the bottom. This 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, leave the default setting of Create a strong name key file, and click Next.
On the Review Details of the Domain-Specific Language Solution page, review the settings that you have specified.
If changes are necessary, click Previous to make corrections.
When you are satisfied with the settings, click Finish.
The system creates a solution called FamilyTree based on the name that you specified and the Minimal Language solution template. The solution has two projects, which are named Dsl and DslPackage.
注意
When you create a project, the system automatically generates default text templates. When you generate a text template, you will see a message that warns you not to run text templates from untrusted sources. If you do not want this message to appear again, select the Do not show this message again check box, and click OK. Otherwise, click OK.
Next Steps
At this stage, you have created a domain-specific language solution. This solution has the required name and language extension that defines a minimal language.
In Walkthrough: Customizing the Domain-Specific Language Definition, you continue to define the domain-specific language for the family tree. As you follow the steps, you can find detailed explanations of how to use the domain model designer and of the notation used to define domain-specific languages. After you finish the second walkthrough, the domain-specific language will allow inconsistencies such as setting a child’s birth date to be before those of at least one of its parents. In Walkthrough: Adding Validation to a Domain Model, you can add validation to check for and inform users of this mistake. Your validation will identify the problem by comparing birth dates.
See Also
Concepts
Creating Domain-Specific Language Solutions
How to: Create Domain-Specific Language Solutions