How to add a task to a preset

Info

It's recommended to consult the LLBLGen Pro SDK for details about the task/preset/template system, file formats and available parameter values. You can find the SDK documentation on the website

To execute a template you have to run a task. To do so you have to add a task specificiation to a preset. To add a task to a preset, you open the Preset Viewer to open the preset you want to add the task to in the editor. It's recommended to use copies of the shipped presets instead of editing them directly. The Preset Viewer makes it easy to create a copy of a shipped preset to add your task to.

Presets configure defines tasks for a given situation. Below first the task xml is given and after that the taskPreset xml, which configures the task. It's not necessary to specify all parameters in the taskPreset: if you're fine with the default values for optional parameters you don't have to specify the parameter in the taskPreset.

There are two different general tasks which you'll use when adding templates: the SD.Tasks.Base.ConsumeLptTemplate task and the SD.Tasks.Base.ConsumeTDLTemplate task. The former is used to execute .lpt templates written in C# and is recommended, the latter is used for executing .template templates written in TDL. For both a preset is specified below. To work with a preset, please open it in the Text Editor by clicking Edit as XML in the Preset Viewer.

Adding a .lpt template taskPreset

To add a taskPreset which executes a .lpt lpt template, you have to use the general SD.Tasks.Base.ConsumeLptTemplate task:

<task name="SD.Tasks.Base.ConsumeLptTemplate" 
    assemblyFilename="SD.LLBLGen.Pro.LptParser.dll" 
    taskPerformerClass="SD.LLBLGen.Pro.LptParser.DotNetTemplateEngine"
    description ="Consumes a .lpt template and generates code using that template and the meta-data specified with the emitType parameter."
    isOptional="true">
    <supportedPlatforms/>
    <supportedTemplateGroups/>
    <dependencies/>
    <parameters>
        <parameter name="destinationFolder" defaultValue="FolderName" isOptional="false" description="The folder to generate the code in"/>
        <parameter name="filenameFormat" defaultValue="[elementName].[extension]" isOptional="false" description="The destination file format specification"/>
        <parameter name="templateID" defaultValue="SD_TemplateID" isOptional="false" description="The ID of the template to use." valueType="templateID"/>
        <parameter name="emitType" defaultValue="generic" isOptional="false" description="The type of code generation to perform." valueType="emitType"/>
        <parameter name="failWhenExistent" defaultValue="false" isOptional="true" description="Flag to signal what to do when the destination file already exists." valueType="boolean"/>
        <parameter name="templateBindingDefinitionName" defaultValue="" isOptional="true" description="The name of the TemplateBindings from which to pick the templateID specified. Specifying this parameter will always force the templateID to be picked from the templateBindings with the name specified."/>
        <parameter name="compileOnly" defaultValue="false" isOptional="true" description="Flag to signal if the templates should just be compiled, but not run" valueType="boolean"/>
        <parameter name="debugBuild" defaultValue ="false" isOptional="true" description ="Flag to signal that the templates have to be compiled using a debug compile, so debugging the templates can be done more easily." valueType="boolean"/>
        <parameter name="templateIsOptional" defaultValue="false" isOptional="true" description="This optional parameter is a boolean flag which signals the task performer to report a missing template ID as an error (false, default) or as a normal description (true). Used on tasks which are optional for certain databases, like stored procedure call class generation tasks." valueType="boolean"/>
        <parameter name="templateAssemblySourceFileFormat" defaultValue="templatesSource.[extension]" isOptional="true" description="The filename format for the template sourcecode as it's compiled. Use for debugging templates."/>
        <parameter name="elementFilter" defaultValue="" isOptional="true" description="This filter will accept the body of a lambda for filtering in string format, according to the DynamicQuery example for C#, shipped with VS.NET. The filter is used to filter elements in the set to process. Example: 'Fields.Count &gt; 0' (without the quotes) which can be used to allow only entities which have fields" valueType="string"/>
        <parameter name="dependentUponFilenameFormat" defaultValue="" isOptional="true" description="The dependentupon filename format specification for the file the output of this task is dependent upon. Default: empty string" valueType="string"/>
    </parameters>
</task>

The above task can be executed using the following taskPreset xml in your preset, inside the <taskPresets> </taskPresets> element:

<taskPreset name="SD.Tasks.Base.ConsumeLptTemplate" displayName="your task name" >
    <parameters>
        <parameter name="destinationFolder" value="FolderName"/>
        <parameter name="filenameFormat" value="[elementName].[extension]"/>
        <parameter name="templateID" value="SD_TemplateID"/>
        <parameter name="emitType" value="generic"/>
        <parameter name="failWhenExistent" value="false"/>
        <parameter name="templateBindingDefinitionName" value=""/>
        <parameter name="compileOnly" value="false"/>
        <parameter name="debugBuild" value ="false"/>
        <parameter name="templateIsOptional" value="false"/>
        <parameter name="templateAssemblySourceFileFormat" value="templatesSource.[extension]" />
        <parameter name="elementFilter" value=""/>
        <parameter name="dependentUponFilenameFormat" value=""/>
    </parameters>
</taskPreset>

Not every parameter has to be specified, you can remove the ones which are optional and have a default value which is OK for your preset.

Adding a TDL template taskPreset

To add a taskPreset which executes a .template TDL template, you have to use the general SD.Tasks.Base.ConsumeTDLTemplate task:

<task name="SD.Tasks.Base.ConsumeTDLTemplate" 
    assemblyFilename="SD.LLBLGen.Pro.TaskPerformers.dll" 
    taskPerformerClass="SD.LLBLGen.Pro.TaskPerformers.CodeEmitter"
    description ="Consumes a TDL template and generates code using that template and the meta-data specified with the emitType parameter."
    isOptional="true">
    <supportedPlatforms/>
    <supportedTemplateGroups/>
    <dependencies/>
    <parameters>
        <parameter name="destinationFolder" defaultValue="FolderName" isOptional="false" description="The folder to generate the code in"/>
        <parameter name="filenameFormat" defaultValue="[elementName].[extension]" isOptional="false" description="The destination file format specification"/>
        <parameter name="templateID" defaultValue="SD_TemplateID" isOptional="false" description="The ID of the template to use." valueType="templateID"/>
        <parameter name="emitType" defaultValue="generic" isOptional="false" description="The type of code generation to perform." valueType="emitType"/>
        <parameter name="templateBindingDefinitionName" defaultValue="" isOptional="true" description="The name of the TemplateBindings from which to pick the templateID specified. Specifying this parameter will always force the templateID to be picked from the templateBindings with the name specified."/>
        <parameter name="templateIsOptional" defaultValue="false" isOptional="true" description="This optional parameter is a boolean flag which signals the task performer to report a missing template ID as an error (false, default) or as a normal description (true). Used on tasks which are optional for certain databases, like stored procedure call class generation tasks." valueType="boolean"/>
        <parameter name="failWhenExistent" defaultValue="false" isOptional="true" description="Flag to signal what to do when the destination file already exists." valueType="boolean"/>
        <parameter name="elementFilter" defaultValue="" isOptional="true" description="This filter will accept the body of a lambda for filtering in string format, according to the DynamicQuery example for C#, shipped with VS.NET. The filter is used to filter elements in the set to process. Example: 'Fields.Count &gt; 0' (without the quotes) which can be used to allow only entities which have fields" valueType="string"/>
        <parameter name="dependentUponFilenameFormat" defaultValue="" isOptional="true" description="The dependentupon filename format specification for the file the output of this task is dependent upon. Default: empty string" valueType="string"/>
    </parameters>
</task>

The above task can be executed using the following taskPreset xml in your preset, inside the <taskPresets> </taskPresets> element:

<taskPreset name="SD.Tasks.Base.ConsumeTDLTemplate" displayName="your task name">
    <parameters>
        <parameter name="destinationFolder" value="FolderName"/>
        <parameter name="filenameFormat" value="[elementName].[extension]"/>
        <parameter name="templateID" value="SD_TemplateID"/>
        <parameter name="emitType" value="generic"/>
        <parameter name="templateBindingDefinitionName" value=""/>
        <parameter name="templateIsOptional" value="false"/>
        <parameter name="failWhenExistent" value="false"/>
        <parameter name="elementFilter" value=""/>
        <parameter name="dependentUponFilenameFormat" value=""/>
    </parameters>
</taskPreset>

Not every parameter has to be specified, you can remove the ones which are optional and have a default value which is OK for your preset.