ASP.NET 5 (VS 2015) 中的设计时 T4 模板
Design-time T4 templates in ASP.NET 5 (VS 2015)
我似乎无法在 ASP.NET 5 (vNext) 项目中找到在 VS 2015 RTM 中制作 T4 模板的方法。
我什至安装了 T4 toolbox for Visual Studio 2015 扩展,但是 tt
模板没有转换。
属性 Custom Tool
没有出现在 tt
文件属性中,我也找不到 '运行 自定义工具'命令。
更新
我想要 T4 模板的原因是 config.json
文件和可插入配置系统的引入,这是一件很棒的事情,但代价是没有强类型的设置属性.
我已经阅读了 this 文章,解释了如何实现这一目标,但仍然没有生成。由于我有一个相当复杂的配置结构,我考虑制作一个 T4 模板来生成一个 AppSettings
文件。显然也欢迎对此提出任何想法。
如果您观看 Julie Lerman 的 pluralsight 视频:http://www.pluralsight.com/courses/entity-framework-7-looking-ahead 她解决了这个问题。目前还没有计划在即将推出的 Visual Studio 版本中删除 T4 模板,但它们并没有在发布中出现。您总是在数据库上编写 运行 逆向工程工具,并采用代码优先方法,稍后再切换回来(尽管我不知道您为什么会这样做),但这将是一个解决方法,直到有有关当前 VS 版本中 T4 模板的更多信息。
ASP.Net 5 (vnext) 项目是一个全新的项目,技术上仍处于测试阶段,它不是 scheduled for RC til November 2015. Also it's attempting to be completely cross platform so initially the team favored using razor templates instead of T4 for scaffolding. They had no plans to support T4 (or any single file generators) at all until an out cry from the community made them change their mind. According to that thread they will support it but have given no dates. They do seem to have made progress, back in January when I was testing my T4 extension I had issues with the project file(now in json format) not supporting custom properties but as of the release on 7/20/2015 it seems to work now. The engine for running T4 inside of visual studio 2015 is still there so you can use it if you like from other project types. You can create a console app and have it store the T4 files but generate them in the vnext project. If you want a cleaner solution you can also try out my extension T4 Awesome,它为您提供了一种通过右键单击菜单组织和调用模板的方法.
我发现在使用 ASP.NET 5 RC1 构建 ASP.NET 5 项目时,我仍然可以使用 Modeling SDK for Microsoft Visual Studio 2015 附带的 MSBuild 目标。
我是通过修改来自
MSDN - Code Generation in a Build Process.
- 将 *.tt 和输出文件(在我的例子中是 *.cs)添加到项目文件夹结构中。
- 卸载并编辑项目的 *.xproj 文件。
在 Microsoft.DNX.targets 导入之后添加以下导入元素:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TextTemplating\Microsoft.TextTemplating.targets" />
添加一个类似于以下内容的 ItemGroup 元素(我在导入语句之前添加了它):
<ItemGroup>
<Content Include="MyTemplate.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MyTemplate.cs</LastGenOutput>
</Content>
</ItemGroup>
可选地,您可以将元素添加到 Globals PropertyGroup 元素以控制转换任务:
<TransformOnBuild>true</TransformOnBuild>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
重新加载项目的*.xproj并正常构建。
我使用的模板非常简单,因此我可能遗漏了这种方法的局限性。
我似乎无法在 ASP.NET 5 (vNext) 项目中找到在 VS 2015 RTM 中制作 T4 模板的方法。
我什至安装了 T4 toolbox for Visual Studio 2015 扩展,但是 tt
模板没有转换。
属性 Custom Tool
没有出现在 tt
文件属性中,我也找不到 '运行 自定义工具'命令。
更新
我想要 T4 模板的原因是 config.json
文件和可插入配置系统的引入,这是一件很棒的事情,但代价是没有强类型的设置属性.
我已经阅读了 this 文章,解释了如何实现这一目标,但仍然没有生成。由于我有一个相当复杂的配置结构,我考虑制作一个 T4 模板来生成一个 AppSettings
文件。显然也欢迎对此提出任何想法。
如果您观看 Julie Lerman 的 pluralsight 视频:http://www.pluralsight.com/courses/entity-framework-7-looking-ahead 她解决了这个问题。目前还没有计划在即将推出的 Visual Studio 版本中删除 T4 模板,但它们并没有在发布中出现。您总是在数据库上编写 运行 逆向工程工具,并采用代码优先方法,稍后再切换回来(尽管我不知道您为什么会这样做),但这将是一个解决方法,直到有有关当前 VS 版本中 T4 模板的更多信息。
ASP.Net 5 (vnext) 项目是一个全新的项目,技术上仍处于测试阶段,它不是 scheduled for RC til November 2015. Also it's attempting to be completely cross platform so initially the team favored using razor templates instead of T4 for scaffolding. They had no plans to support T4 (or any single file generators) at all until an out cry from the community made them change their mind. According to that thread they will support it but have given no dates. They do seem to have made progress, back in January when I was testing my T4 extension I had issues with the project file(now in json format) not supporting custom properties but as of the release on 7/20/2015 it seems to work now. The engine for running T4 inside of visual studio 2015 is still there so you can use it if you like from other project types. You can create a console app and have it store the T4 files but generate them in the vnext project. If you want a cleaner solution you can also try out my extension T4 Awesome,它为您提供了一种通过右键单击菜单组织和调用模板的方法.
我发现在使用 ASP.NET 5 RC1 构建 ASP.NET 5 项目时,我仍然可以使用 Modeling SDK for Microsoft Visual Studio 2015 附带的 MSBuild 目标。
我是通过修改来自 MSDN - Code Generation in a Build Process.
- 将 *.tt 和输出文件(在我的例子中是 *.cs)添加到项目文件夹结构中。
- 卸载并编辑项目的 *.xproj 文件。
在 Microsoft.DNX.targets 导入之后添加以下导入元素:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TextTemplating\Microsoft.TextTemplating.targets" />
添加一个类似于以下内容的 ItemGroup 元素(我在导入语句之前添加了它):
<ItemGroup> <Content Include="MyTemplate.tt"> <Generator>TextTemplatingFileGenerator</Generator> <LastGenOutput>MyTemplate.cs</LastGenOutput> </Content> </ItemGroup>
可选地,您可以将元素添加到 Globals PropertyGroup 元素以控制转换任务:
<TransformOnBuild>true</TransformOnBuild> <TransformOutOfDateOnly>false</TransformOutOfDateOnly> <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
重新加载项目的*.xproj并正常构建。
我使用的模板非常简单,因此我可能遗漏了这种方法的局限性。