question

DavidReis-4518 avatar image
0 Votes"
DavidReis-4518 asked JackJJun-MSFT commented

T4 text templating in .NET Core and above

After some testing, it looks like the TextTemplating library that is part of VisualStudio (Microsoft.VisualStudio.TextTemplating.15.0.dll) can't be used in the newer "dotnet" command line toolchain as it depends on the WPF assembly WindowsBase.dll. This causes the .tt code generation to fail, even on a Windows machine.

After some investigation, we found some open-source projects that are able to do .tt code generation, most notably mono/t4, but these solutions have the disadvantage of not being so well integrated with VisualStudio as the current TextTemplating is. For example, it's harder (if not impossible) to get design-time generation and we also lose the ability to trigger the code generation from the context menu in the solution explorer.

Given these drawbacks, I'd just like to know what is Microsoft's position on this. Is there a plan to update the existing TextTemplating libraries so that they are compatible with the "dotnet" toolchain while still maintaining good integration within the VS IDE? Or is TextTemplating being left behind and we must rely on the not-so-well-integrated open-source solutions?


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered JackJJun-MSFT commented

See this thread

https://developercommunity.visualstudio.com/t/build-transform-all-t4-templates-not-working-for-d/446832

If can add t4 templates as a build step in a .net core project, but the step is only called on build, not run

https://github.com/nogic1008/T4Sample

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer but that's a different issue - I'm trying to get the command line toolchain "$- dotnet" to be able to import and use the text templates.

Also, one of the key things that I'd like to keep is, as I mentioned, design-time generation instead of build-time generation. Meaning that I want the code to be generated when I save the .tt file in VisualStudio, which is something that we do right now with VisualStudio's TextTemplating tool.

0 Votes 0 ·

@DavidReis-4518, I suggest that you could report a problem about your issue in Developer Community.


0 Votes 0 ·