Generated T4 files on assembly

I am having difficulty converting T4 on build (using MsBuild).

I am trying to get the generated files in a solution / project. If I just save or run the custom tool, the files are generated and automatically added to the solution.

Files are also generated on build, but not included out of the box. I'm not sure if this is my fault or the default behavior.

I cannot get the generated filenames in the template.

I can see the generated files in the build output, but unsuccessfully pass them as a parameter to the .tt file.

This is what the .csproj looks like:

  <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 let's build the output:

  • 1> ------ Build started: Project: DTE_transform_T4_on_build, Configuration: Debug Any processor ------
  • 1> Transforming Template TransformMe.tt ...
  • 1> Transforming AnotherOneForTest.tt template ...
  • 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 failed, 0 failed, 0 updated, 0 skipped ==========

GeneratedFiles are visible here, but in .tt, if I try any of them:
<#@ parameter type="System.Collections.Generic.List<string>" name="Generated" #>
<#@ parameter type="System.String" name="Generated" #>
<#@ parameter type="System.String" name="GeneratedFiles" #>

      

... I cannot get these filenames into the .tt file. I don't know what type I should be using for the parameter. From the Oleg and others page , I couldn't tell the type of the parameter. I also couldn't find a suitable googling example.

On the other hand, I can easily pass the 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 is:

  • what do I need to do to get the generated files into a solution when converting by build
  • How to pass generated files to .tt on build
+3


source to share





All Articles