Шаблоны T4 не преобразуются во время сборки - PullRequest
1 голос
/ 23 апреля 2020

Что я сделал

Я попытался скомпилировать свои шаблоны T4 в файл c#.

То, что я попробовал из Microsoft: вызвать преобразование текста в сборке process

Добавив в мой файл .csproj:

  <Import Project="TextTemplating\Microsoft.TextTemplating.targets" />
  <PropertyGroup>
    <TransformOnBuild>true</TransformOnBuild>
    <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
  </PropertyGroup>
  <ItemGroup>
    <T4ParameterValues Include="ProjectDir">
      <Value>$(ProjectDir)</Value>
      <Visible>false</Visible>
    </T4ParameterValues>
  </ItemGroup>

TextTemplating - это каталог, содержащий файлы TextTemplating из моего редактора, расположенный по адресу: C: \ Program Files (x86) \ Microsoft Visual Studio \ 2019 \ Enterprise \ msbuild \ Microsoft \ VisualStudio \ v16.0 \ TextTemplating

Шаблоны

Базовый шаблон (с именем ModelTemplate.tt):

<#@ template language="C#" #>
<#@ parameter name="ClassName" type="System.String"#>
<#@ parameter name="Namespace" type="System.String"#>

namespace <#= Namespace #> 
{
    public class <#= ClassName #>
    {

    }
}

И, наконец, шаблон для тестирования ModelTemplate.tt (с именем ModelTemplateTest.tt):

<#@ template debug="false" language="C#" #>
<#@ output extension=".cs" #>
<#
    _ClassNameField = "Model";
    _NamespaceField = "MyNamespace";
#>
<#@ include file="$(ProjectDir)\Templates\ModelTemplate.tt"#>

Вывод из сборки

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.       

НО ModelTemplateTest.tt скомпилирован в:

namespace MyNamespace 
{
    public class Model
    {

    }
}

Как я могу вызвать 'TextTemplatingFilePreprocessor' в моей сборке?

...