【问题标题】:How to get Visual Studio to transform specific T4 Templates on build?如何让 Visual Studio 在构建时转换特定的 T4 模板?
【发布时间】:2019-01-03 02:27:22
【问题描述】:

是否可以让 Visual Studio 在构建时仅构建一组特定的 T4 模板?

目前我使用here 提供的解决方案在构建时使 Visual Studio 转换我的 T4 模板文件的所有。但是,我有一个 T4 模板,当它在构建时转换时会运行到 this issue。因此,我想转换所有模板除了这个特定的模板。

更具体地说,我的.csproj 中有以下代码:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <TransformOnBuild>true</TransformOnBuild>
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
    <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
</PropertyGroup>

哪个“有效”可以按照我想要的方式重建我的大部分 T4 模板。

但是,我在 .csproj 中包含一个 T4 模板,它使用了 Host 变量,导致转换在构建期间失败(请参阅 here)。

除了后者之外的所有模板都必须在构建时进行转换,那么有什么方法可以实现这种行为吗?

注意:这种类型的 &lt;PropertyGroup&gt; 在多个解决方案中的多个项目中使用,因此为了保持整体相同,如果可能的话,我更愿意继续使用它进行转换.

【问题讨论】:

    标签: visual-studio tfs msbuild t4


    【解决方案1】:

    为您不想转换的模板的元数据项添加条件,如下所示:

    <Content Include="TextTemplate2.tt" >
      <Generator Condition="$(BuildingInsideVisualStudio)=='true'">TextTemplatingFileGenerator</Generator>
      <LastGenOutput>TextTemplate2.txt</LastGenOutput>
    </Content>
    

    这将阻止 Microsoft.TextTemplating.targets 将文件识别为需要转换的文件,除非在 Visual Studio 中构建。

    【讨论】:

      猜你喜欢
      • 2010-12-11
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 2011-01-19
      • 1970-01-01
      相关资源
      最近更新 更多