T4 parameter directive using .Net Core
Asked Answered
A

1

5

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.

Anabantid answered 27/3, 2020 at 17:1 Comment(3)
Related (error at design-time, not runtime): #51550765 Otherwise, lacking support for t4, you may want to consider Roslyn code gen instead (by hacking around with something like this): carlos.mendible.com/2017/03/02/…Kirshbaum
@FrankAlvaro NET Core does not support .NET Remoting , this is the problem and i search for a workaroundAnabantid
Look at the Roslyn link in my previous comment. That should be compatibleKirshbaum
G
8

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);
Generic answered 20/3, 2021 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.