Product of build-time T4 transformation is used only in the next build

前端 未结 2 1352
迷失自我
迷失自我 2020-12-18 21:09

I have a VS project that contains:

  1. a pre-build action running TextTransform on a template.tt to generate generated.cs

相关标签:
2条回答
  • 2020-12-18 21:32

    I don't think you need a custom pre-build action. Just add the ".tt" file to your project and set its "Custom Tool" property to "TextTemplatingFileGenerator". You might want to make sure that the *.generated.cs files are also added to the project, but I think that VS takes care of that.

    0 讨论(0)
  • 2020-12-18 21:32

    There's now a solution to this problem! Oleg Sych has a post on his blog detailing how to make transform-at-build-time work.

    Here's the source: https://web.archive.org/web/20140116193428/http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/

    Basically, you just include the T4 build targets in your project file and set the TransformOnBuild property to true.

    Here's the relevant excerpt:

    <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
      <PropertyGroup>
        <TransformOnBuild>true</TransformOnBuild>
      </PropertyGroup>
    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />
    

    Note that the Microsoft.TextTemplating.targets file has to be included AFTER the Microsoft.CSharp.targets.

    0 讨论(0)
提交回复
热议问题