简体   繁体   English

我想在 csproj 中使用通配符设置 T4 模板

[英]I want to setting T4 Template with wildcard in csproj

What I do我所做的

I have multiple tt files in my project file.我的项目文件中有多个 tt 文件。 Therefore, many entries are created for each file as follows.因此,为每个文件创建了许多条目,如下所示。

<ItemGroup>
  <Compile Update="Sample.cs">
    <DesignTime>True</DesignTime>
    <AutoGen>True</AutoGen>
    <DependentUpon>Sample.tt</DependentUpon>
  </Compile>
</ItemGroup>

<ItemGroup>
  <None Update="Sample.tt">
    <Generator>TextTemplatingFileGenerator</Generator>
    <LastGenOutput>Sample.cs</LastGenOutput>
  </None>
</ItemGroup>

I want to prevent making this entry for every tt file.我想防止为每个 tt 文件创建此条目。

What I have tried我试过的

The following statements were made using wildcards.以下语句是使用通配符进行的。

<ItemGroup>
  <Compile Update="**/*.tt.cs">
    <DesignTime>True</DesignTime>
    <AutoGen>True</AutoGen>
    <DependentUpon>%(Filename)</DependentUpon>
  </Compile>
  <None Update="**/*.tt">
    <Generator>TextTemplatingFileGenerator</Generator>
    <LastGenOutput>%(Filename).tt.cs</LastGenOutput>
  </None>
</ItemGroup>

The following settings are used in the tt file. tt 文件中使用了以下设置。

<#@ output extension="tt.cs" #>

Problem问题

T4 works, but when I save the tt file, the following entry is added to csproj. T4 工作,但是当我保存 tt 文件时,以下条目被添加到 csproj。

<ItemGroup>
  <Compile Update="Sample.tt.cs">
    <DesignTime>True</DesignTime>
  </Compile>
</ItemGroup>

Question问题

How can I prevent entries from being added?如何防止添加条目?

We can see the description of Update from this page我们可以从这个页面看到更新的描述

Enables you to modify metadata of an item;使您能够修改项目的元数据; typically used to override the default metadata of specific items after a group of items is intially specified (such as with a wildcard).通常用于在最初指定一组项目后覆盖特定项目的默认元数据(例如使用通配符)。

Update overrides Compile when save the tt file, so this code will be added to scproj.保存 tt 文件时更新会覆盖编译,因此此代码将添加到 scproj。 This doesn't seem to prevent.这似乎并不能阻止。

<ItemGroup>
  <Compile Update="Sample.tt.cs">
    <DesignTime>True</DesignTime>
  </Compile>
</ItemGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM