【问题标题】:T4 precompilation on build?构建时的 T4 预编译?
【发布时间】:2017-01-31 00:01:40
【问题描述】:

使用带有 SP2 的 MS Studio Community 2015。

我需要在构建时重新编译 T4。

我确实添加到项目中:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v14.0\TextTemplating\Microsoft.TextTemplating.targets" />

<PropertyGroup>
<TransformOnBuild>true</TransformOnBuild>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>

这个强制重新编译T4的。

但是编译有一个问题——没有使用为特定 T4 提供的 CustomToolNamespace,而是使用了通用的 RootNamespace。结果是一场彻底的灾难。

我在项目文件中使用了 CustomToolNamespace 的位置,但没有得到肯定的结果。

告诉我去哪里看 - 仍然尝试使用 *.csproj 或开始寻找调试 Microsoft.TextTemplating.targets?

或者只是生成“tempalaterecompilation.bat”并在预构建时运行它?我非常不喜欢这种方式。

【问题讨论】:

    标签: t4


    【解决方案1】:

    我确实检查了 Microsoft.TextTemplating.targets。 它包含命名空间的定义

    <PropertyGroup>
      <!-- Unless another namespace has been specified, use the project namespace as the
      default namespace from pre-processed files. -->
      <PreprocessTemplateDefaultNamespace Condition=" $(PreprocessTemplateDefaultNamespace)=='' ">$(RootNamespace)</PreprocessTemplateDefaultNamespace>
    </PropertyGroup>
    

    所以,RootNamespace 是有意使用的。

    为了让目标使用为模板定义的 CustomToolNamespace,我需要进行哪些更改?

    【讨论】:

      【解决方案2】:

      我确实找到了问题的临时解决方案。

      很少有地方可以提取命名空间。

      其中之一 - 内容部分中的 ClassNamespace。如果指定了这个,给定的值将被用作命名空间。

      但这是解决方法,我仍在寻找使用 *.targets 的解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-06
        • 2017-03-18
        • 1970-01-01
        • 1970-01-01
        • 2013-06-18
        • 2011-11-04
        • 2021-04-22
        • 2011-01-19
        相关资源
        最近更新 更多