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
msbuild t4


source to share


No one has answered this question yet

Check out similar questions:

328
Found conflicts between different versions of the same dependent assembly that could not be resolved
235
MSBuild does not copy references (DLL files) when using project dependencies in solution
188
How do I publish the Web with msbuild?
159
Get Visual Studio to run T4 template for each build
22
Generated (by T4) Build Action file gets reset for build
nine
Generating T4 code at build time, assembly reference
five
Creating T4 in assembly using VS 2012
4
Unable to perform T4 text transformation on build server
3
How do I auto-build or version a build file from MSBuild?
0
The assembly fails because the type that was converted from t4 in the assembly was not found



All Articles
Loading...
X
Show
Funny
Dev
Pics