RdJNL / TextTemplatingCore

T4 Text Templating with .NET 6
Other
57 stars 15 forks source link

c# try .. catch appears to be not supported #18

Open jobyjcteoco opened 8 months ago

jobyjcteoco commented 8 months ago

Hello,

Thank you so much for this library which allows us to write T4 files for the .Net core assemblies. Since debugging is not available with this library, I was trying to find out the issues with our template files which used to work with old gen engine by adding Try.. Catch sections, but it doesn't appear to be honouring those and always outputting 'ErrorGeneratingOutput' in the generated file which doesn't help much in diagnosing the issues. I have added a simple template here which deliberately creates an exception here:

<#@ template hostspecific="false" debug="false" language="C#" #>
<#@ output extension=".generated.txt" encoding="utf-8" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Text.Json" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text.Json" #>
<#@ import namespace="System.Text.Json.Serialization" #>
<# BuildTests("Jack"); #>
<#+
    void BuildTests(string param)
    {
    try
        {
        #>
        Hello <#= param #>
        <#+
            var a = 10/0; //To get an exception

            #>
            Number: <#= a #>
        <#+
        }
        catch(Exception ex)
        {
        #>
            Error: <#= ex.ToString() #>
        <#+
        }
    }
#>

Any advice is much appreciated which would allow us to find and fix the issues with our template files.

Kind regards, Joby