T4.Build is a tool to automatically transform T4 templates during build.
It is similar to the functionality provided by Visual Studio, except it works anywhere where you have a .NET (Core) runtime installed.
It is fully integrated with MSBuild and supports transforming the templates during the build process, and cleaning the 7422 m during the clean process.
T4.Build aims for performance by transforming only the templates that have changed, and doing so in parallel (so more CPU cores => faster).
Just add these lines to your project file:
<ItemGroup>
<PackageReference Include="T4.Build" Version="0.2.5" PrivateAssets="All" />
</ItemGroup>
That's it!
Now the next time you run dotnet build
, your templates will be transformed before compilation happens 🚀
If you want to clean all the generated files, just do a regular dotnet clean
and they will be gone 🧹
This also works with the 'Build/Rebuild/Clean' buttons in Visual Studio. No need to click 'Transform All T4 Templates' anymore 💪🏽
The following properties can be defined in your project file to further control how T4.Build works:
TextTemplateTransformSkipUpToDate
(default:true
): Indicates whether only out of date templates should be transformed, or whether all templates should be transformedTextTemplateTransformParallel
(default:true
): Indicates whether templates should be transformed in parallel, or whether they should be transformed sequentiallyTextTemplateTransformAll
(default:true
): Indicates whether all *.tt files should be automatically transformed. Otherwise T4.Build will only look forNone
items whoseGenerator
is set toTextTemplatingFileGenerator
(that's the default when creating a new text template in Visual Studio).TextTemplateTransformOnBuild
(default:true
): Indicates whether template transform/clean should happen automatically during build/clean
You can specify the list of text templates to transform manually via the TextTemplateTransformFiles
item:
<ItemGroup>
<TextTemplateTransformFiles Include="MyTemplate.custom;AnotherOne.custom" />
</ItemGroup>
If you disable TextTemplateTransformOnBuild
, you can run the tasks manually via MSBuild:
dotnet msbuild -t:TextTemplateTransform
dotnet msbuild -t:TextTemplateClean