Get Visual Studio to run a T4 Template on every build

后端 未结 22 2872
余生分开走
余生分开走 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:16

    Here's a pre-build event using only Microsoft Tooling and standard paths. It's tested in vs2019/netcore3.1.

    Replace "AppDbContext.tt" with your project-relative file path:

    "$(MSBuildBinPath)\msbuild" $(SolutionPath) /t:$(ProjectName):Transform /p:TransformFile="AppDbContext.tt" /p:CustomAfterMicrosoftCommonTargets="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TextTemplating\Microsoft.TextTemplating.targets"
    

    Microsoft also has a guide to make macros like "$(SolutionDirectory)" available in the template by using T4ParameterValues in your project file.

提交回复
热议问题