T4 parameter directive using .Net Core

811 Views Asked by At

I have an issue in "CallContext.LogicalGetData" method using .net Core when i try to send parameter to runtime text template t4 (net core)

Below tt file :

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ parameter name="firstName" type="System.String" #>
<#@ parameter name="lastName" type="System.String" #>

and Cs call method :

            var pt1 = new ParamTemplate1();
            pt1.Session = new Dictionary<string, object>();
            pt1.Session["firstName"] = "David";
            pt1.Session["lastName"] = "Giard";
            pt1.Initialize();
            var outputText1 = pt1.TransformText();
            Console.WriteLine(outputText1);
             Hello <#=firstName #> <#=lastName #>!

the problem is du to " System.Runtime.Remoting" library is not supported in .net core

Any ideas or workaround ??

Thanks.

1

There are 1 best solutions below

0
frank_lbt On

Sorry for the late reply, but if you still want to use the t4 templates, you can replace the parameters directives with properties at the end of the t4 document:

<#+
    public string FirstName { get; set; }
    public string LastName { get; set; }
#>

And then call it:

var pt1 = new ParamTemplate1
{ 
    FirstName = "David",
    LastName = "Giard"
};
var outputText1 = pt1.TransformText();
Console.WriteLine(outputText1);