I'm having difficulties with T4 transforming on build (with MsBuild).
I'm trying to get generated files to the solution/project. If I just save or run custom tool, files are generated, and added to the solution automatically.
The files are also generated on build, but are not added to the solution "out of the box". I'm not sure, if this is my fault, or default behaviour.
I can't get generated file names to the template, either.
I'm able to see generated files in build output, but am unsuccessful passing them as a parameter to the .tt file.
Here's how .csproj looks:
<Import Project="$(VSToolsPath)\TextTemplating\Microsoft.TextTemplating.targets" />
<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<AfterTransform>OnAfterTransform</AfterTransform>
</PropertyGroup>
<Target Name="OnAfterTransform">
<Message Text="@(GeneratedFiles)" Importance="high" />
<ItemGroup>
<T4ParameterValues Include="Generated">
<Value>@(GeneratedFiles)</Value>
<Visible>false</Visible>
</T4ParameterValues>
</ItemGroup>
</Target>
And build output:
- 1>------ Build started: Project: DTE_transform_T4_on_build, Configuration: Debug Any CPU ------
- 1> Transforming template TransformMe.tt...
- 1> Transforming template AnotherOneForTest.tt...
- 1> C:\Users\Me\Documents\Visual Studio 2013\Projects\Transform_T4_on_build\Transform_T4_on_build\TransformMe.generated.cs;C:\Users\Me\Documents\Visual Studio 2013\Projects\Transform_T4_on_build\Transform_T4_on_build\AnotherOneForTest.txt
- 1> Transform_T4_on_build -> C:\Users\Me\Documents\Visual Studio 2013\Projects\Transform_T4_on_build\Transform_T4_on_build\bin\Debug\Transform_T4_on_build.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
<#@ parameter type="System.Collections.Generic.List<string>" name="Generated" #>
<#@ parameter type="System.String" name="Generated" #>
<#@ parameter type="System.String" name="GeneratedFiles" #>
... I can't get those file names into .tt file. I don't really know what type should I use for the parameter. From Oleg's page and others, I couldn't really tell the type of parameter. I was unsuccessful finding relevant example by googling as well.
On the other hand, I can easily pass ProjectFolder for example:
<ItemGroup>
<T4ParameterValues Include="ProjectFolder">
<Value>$(ProjectDir)</Value>
<Visible>false</Visible>
</T4ParameterValues>
</ItemGroup>
and consume it with:
<#@ parameter type="System.String" name="ProjectFolder" #>
in the .tt file.
So, my question are:
- what do I need to do, to get generated files into solution, when transforming on build
- how do I pass generated files into .tt on build