Forum:  Custom Templates

Thread:  Custom DotNetTemplateEngine with custom settings and templates in 4.2

vzakanj (User)   Posted on: 23-Jan-2016 00:03:57.
I've added some custom settings to frameworksettings file and want to use them as placeholders in task parameters, e.g. a setting named Foo would be usable as a task performer parameter by specifying it as [Foo] (the same way default placeholders work).

To do this, I've inherited the DotNetTemplateEngine (the project is using .NET Framework 4.5.2) and overriden the Perform method in the following manner:

public override void Perform(
IGenerator executingGenerator,
ITask taskDefinition, Dictionary<string, TaskParameter> parameters)
    var configReader = ProjectConfigurationReader.Create(executingGenerator.ProjectDefinition);
    var resolvedParameters = this.paramResolver.ResolveParams(configReader, parameters);

    base.Perform(executingGenerator, taskDefinition, resolvedParameters);

The ProjectConfigurationReader and ParamResolver are just helper classes which go through the placeholder parameter values and replace them with the values from project definition custom settings.
I've done everything needed to use this custom task performer in the designer (specified custom task performers folder with the resulting dll in it, created custom task definition, created custom templates and templatebindings etc.), but when generating the code the designer shows that there's been an error while compiling the templates: "The type or namespace name 'ITemplateClass' could not be found (are you missing a using directive or an assembly reference?)".
This error doesn't happen if there's at least one task which uses the original DotNetTemplateEngine task performer before my custom task in the designer task queue.

ITemplateClass is located in SD.LLBLGen.Pro.LptParser, so what this error is indicating that the compiler doesn't have an assembly reference to SD.LLBLGen.Pro.LptParser.dll when compiling the template, but the docs state what I've pasted below so I guess the reference should already be there.

From 4.2 docs:

The following assemblies are already referenced by the code produced by the DotNetTemplateEngine:

I've tried copying the SD.LLBLGen.Pro.LptParser assembly to the custom task performers folder as well as all folders which are specified as probing path in the designer configuration file (e.g. ReferencedAssemblies), and adding an assembly reference declaration in the template as specified below, but with no luck.

<$ SD.LLBLGen.Pro.LptParser.dll $>

The only thing that worked is specifying the full path to the assembly:
<$ C:\Program Files (x86)\Solutions Design\LLBLGen Pro v4.2\TaskPerformers\SD.LLBLGen.Pro.LptParser.dll $>

I'm wondering if there's a way not to have to add that declaration to the custom templates or at least just use the assembly name without the full path?

daelmo (Support Team)   Posted on: 26-Jan-2016 06:03:15.
IMHO you don't need to add such reference, as it's already referenced by the code produced by the DotNetTemplateEngine.

Could you share your TaskPerformer code and a list of steps to reproduce the problem? (You can do it in a HelpDesk thread (which is private).

vzakanj (User)   Posted on: 31-Jan-2016 06:40:35.
I'll post the code and an example in a new HelpDesk thread then.
ch (User)   Posted on: 16-Sep-2017 10:16:29.
I fixed it just as the previous person in the first mentioned thread.
I added to the lpt template the exact location of the parser.

using System;
using System.Collections;
using System.Data;
using SD.LLBLGen.Pro.ORMSupportClasses;
<$ D:\Program Files (x86)\Solutions Design\LLBLGen Pro v5.0\TaskPerformers\SD.LLBLGen.Pro.LptParser.dll $>