Design-time T4 templates in ASP.NET 5 (VS 2015)

前端 未结 3 535
旧巷少年郎
旧巷少年郎 2021-01-06 10:35

I can\'t seem to find a way to make T4 templates in VS 2015 RTM, in an ASP.NET 5 (vNext) project.

I even installed the T4 toolbox for Visual Studio 2015 extension, b

3条回答
  •  暖寄归人
    2021-01-06 11:11

    I've found that I can still use the MSBuild targets that ship with the Modeling SDK for Microsoft Visual Studio 2015 when building an ASP.NET 5 project with ASP.NET 5 RC1.

    I got there by modifying the directions from MSDN - Code Generation in a Build Process.

    1. Add the *.tt and the output files (*.cs in my case) to the project folder structure.
    2. Unload and edit the project's *.xproj file.
    3. Add the following Import element after the Microsoft.DNX.targets import:

      
      
    4. Add an ItemGroup element similar to the following (I added this immediately before the import statements):

      
        
          TextTemplatingFileGenerator
          MyTemplate.cs
        
      
      
    5. Optionally, you can add elements to the Globals PropertyGroup element to control the transformation task:

      true
      false
      true
      
    6. Reload the project's *.xproj and build normally.

    The templates I'm using are pretty simple, so there might be limitations of this approach that I'm missing out on.

提交回复
热议问题