Creating the Template in the Generator Template Editor

This time, we'll use the Generator Template Editor to create the template. This will help get you familiar with the Generator Template Editor as well as see how fast it can speed up template development. To get started, launch Visual Studio and select File > New > File from the Visual Studio menu bar.

You can also open a new or existing Visual Studio Project and select Add new item from the Solution Explorer.

This will open the Visual Studio New File Wizard. Next, you will want to select CodeSmith Generator under the General Installed Templates node. Doing this will only show you the available CodeSmith Generator Item Templates.

We are wanting to create a new Visual Basic Generator Template so we will choose the item above by double clicking on the selected item or clicking the Open button.

This will create a new template with some boiler plate code in it to remind you how the various parts of a CodeSmith Generator template fit together. Start by modifying the CodeTemplate directive:

<%@ CodeTemplate Language="VB" TargetLanguage="T-SQL" Description="Create an HTTP Endpoint." %>

The TargetLanguage attribute is used to determine how to syntax highlight the static content of a template. The Description attribute is used to provide a tooltip for the template.

Next, replace the rest of the sample template code with the T-SQL that we want to generate. Now we've got the starting point: a template that turns out completely static SQL.

<%@ CodeTemplate Language="VB" TargetLanguage="T-SQL" Description="Create an HTTP Endpoint." %>
CREATE PROC dbo.PersonAddressTypeProc
AS
    SELECT 
        AddressTypeID, 
        Name, 
        rowguid, 
        ModifiedDate
    FROM
    Person.AddressType
GO
CREATE ENDPOINT GetAddressType
    STATE = STARTED
AS HTTP
(
    PATH = '/AddressType',
    AUTHENTICATION = (INTEGRATED),
    PORTS = (CLEAR),
    SITE = 'localhost'
)
FOR SOAP
(
    WEBMETHOD 'AddressTypeList'
        (NAME='AdventureWorks.dbo.PersonAddressTypeProc'),
    BATCHES = DISABLED,
    WSDL = DEFAULT,
    DATABASE = 'AdventureWorks',
    NAMESPACE = 'http://AdventureWorks/AddressType'
)
GO

Of course, you don't want a static template. The next step is to start making the content dynamic.

Next: Setting up Enumerated Properties