Get Visual Studio to run a T4 Template on every build

后端 未结 22 2833
余生分开走
余生分开走 2020-11-22 08:29

How do I get a T4 template to generate its output on every build? As it is now, it only regenerates it when I make a change to the template.

I have found other ques

22条回答
  •  借酒劲吻你
    2020-11-22 09:17

    You just need to add this command to the pre-build event of the project:

    if $(ConfigurationName) == Debug $(MSBuildToolsPath)\Msbuild.exe  /p:CustomBeforeMicrosoftCSharpTargets="$(ProgramFiles)\MSBuild\Microsoft\VisualStudio\v11.0\TextTemplating\Microsoft.TextTemplating.targets"  $(ProjectPath) /t:TransformAll 
    

    The check on configuration = debug, makes sure that you don't regenerate the code in the release mode, when you do the build on the TFS build server for instance.

提交回复
热议问题