C# T4模板在生成期间未转换 我所做的
我试图将T4模板编译成一个c#文件 我从尝试的内容 通过在my.csproj文件中添加:C# T4模板在生成期间未转换 我所做的,c#,.net,visual-studio,templates,t4,C#,.net,Visual Studio,Templates,T4,我试图将T4模板编译成一个c#文件 我从尝试的内容 通过在my.csproj文件中添加: 真的 真的 假的 $(ProjectDir) 假的 TextTemplating是一个包含我的编辑器中的TextTemplating文件的目录,位于: C:\Program Files(x86)\Microsoft Visual Studio\2019\Enterprise\msbuild\Microsoft\VisualStudio\v16.0\text模板 模板 基本模板(命名为ModelTempl
真的
真的
假的
$(ProjectDir)
假的
TextTemplating
是一个包含我的编辑器中的TextTemplating文件的目录,位于:
C:\Program Files(x86)\Microsoft Visual Studio\2019\Enterprise\msbuild\Microsoft\VisualStudio\v16.0\text模板
模板
基本模板(命名为ModelTemplate.tt):
名称空间
{
公共课
{
}
}
最后是测试ModelTemplate.tt的模板(名为ModelTemplateTest.tt):
生成的输出
但是ModelTemplateTest.tt被编译成:
名称空间MyNamespace
{
公共类模型
{
}
}
如何在我的构建中调用TextTemplatingFilePreprocessor
?可能是一个解决方案,它是一个VS扩展,允许您在项目构建时触发特定T4文件的执行。解决方案(使用Visual Studio Enterprise 2019)是导入$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v16.0\TextTemplating\Microsoft.TextTemplating.targets
位于.csproj
文件中,如下所示:
真的
相关StackOverflow线程:您有没有办法不明确指定“v16.0”?这将需要基于生成机器和更新的VS版本的动态值。@Luishg我对Microsoft生成工具不是很有经验,也许有可能
A custom tool 'TextTemplatingFilePreprocessor' is associated with file 'Templates\ModelTemplate.tt', but the output of the custom tool was not found in the project. You may try re-running the custom tool by right-clicking on the file in the Solution Explorer and choosing Run Custom Tool.