4

Is it possible to transform the **/*.tt file into a *.cs file. Using Azure Devops pipeline?

Otherwise is there a CLI command available for Dotnet core using TextTransform ?

I already test : T5.TextTransform.Tool but is don't work (and deprecated)

Thanks for your help

btbenjamin
  • 593
  • 7
  • 19

2 Answers2

5

How i solve this problem using Devops pipeline + script:

  1. As mention @Leo Liu-MSFT Install dotnet-t4

install global -g

enter image description here

  1. Create powershell script and find tt file

Seach all *.tt file and convert them with the t4 command

enter image description here

Get-ChildItem -Path .\ -Filter *.tt -Recurse -File -Name| ForEach-Object {
    $file = [System.IO.Path]::GetFileName($_);
    $directory = [System.IO.Path]::GetDirectoryName($_)
    "Conversion file : " + $file
    t4 "$directory\$file" -I="$directory"
}

NOTE : It is important to place the T4.ps1 file in the parent directory of your *.tt files

btbenjamin
  • 593
  • 7
  • 19
1

Is it possible to transform the **/*.tt file into a *.cs file. Using Azure Devops pipeline?

The answer is yes.

According to the state of the package T5.TextTransform.Tool:

T5 was a stopgap measure for a time when Mono.TextTemplating was not available for .NET Core. Now that that is no longer the case, T5 is not needed and no longer being maintained. Use Mono.TextTemplating's dotnet-t4 instead.

enter image description here

So, we could use the Mono.TextTemplating instead of T5.TextTransform.Tool.

Besides, there is also an implementation of the TextTransform.exe command-line tool, we could use the command line to transform the .tt file into .cs file:

"%CommonProgramFiles%\Microsoft Shared\TextTemplating\1.2\texttransform.exe" -out %1.cs -P %2 -P "%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.5" %1.tt

Check this thread for some more details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Yes i solved it, thank you for your post it's helped me. I will post new answer with all my step to fix it – btbenjamin Mar 13 '20 at 09:06
  • Do you guys know if this approach would work in a .NET Core 5.0 project? When I try to install the "dotnet-t4" NuGet package in my project, I am getting this error: NU1202: Package dotnet-t4 2.2.1 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package dotnet-t4 2.2.1 supports: netcoreapp3.1 (.NETCoreApp,Version=v3.1) / any – Eddie Oct 25 '21 at 20:12