本文介绍了使T4MVC与ASP.NET 5一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据线程,.tt模板中的最新评论从Visual Studio Update 1开始,ASP.NET 5现在将最终支持.

According to the latest comments in this thread, .tt templates will now after all be supported in ASP.NET 5 starting with Visual Studio Update 1.

哪个IMHO很棒,因为使用 T4MVC 多年之后,我当然不想回到使用魔术字符串作为路线/视图名称(容易出错且不便于重构).

Which IMHO would be great because after using T4MVC for years, I certainly don't wanna go back to using magic strings for route/view names (error prone and not refactoring-friendly).

但是,我不能完全将其与ASP.NET 5 RC和Visual Studio Professional 2015 Update 1一起使用.

However, I can't quite get it to work with ASP.NET 5 RC and Visual Studio Professional 2015 Update 1.

这是我尝试过的:

  1. T4MVC NuGet (3.16.5)添加到空白ASP.NET 5中解决方案:否,CoreCLR抱怨并且没有将.tt文件添加到项目中:
  1. Adding the T4MVC NuGet (3.16.5) to a blank ASP.NET 5 solution: nope, CoreCLR complains and no .tt files are added to project:
  1. 将NuGet添加到经典的ASP.NET 4.6解决方案中,然后通过T4MVC.ttT4MVC.tt.hooks.t4T4MVC.tt.settings.xml手动复制到ASP.NET 5解决方案:Visual Studio确实提供了运行自定义工具"的功能. tt文件....
  1. Add the NuGet to a classic ASP.NET 4.6 solution and manually copy over T4MVC.tt, T4MVC.tt.hooks.t4 and T4MVC.tt.settings.xml to the ASP.NET 5 solution: Visual Studio indeed offers to "Run Custom Tool" on the .tt file....

...但是运行转换会抛出NullReferenceException:

... but running the transformation throws a NullReferenceException:

Severity    Code    Description Project File    Line    Suppression State
Error       Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.GetProjectItem(ProjectItems items, String subPath) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 1398
   at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.GetProjectItem(Project project, String name) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 1378
   at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.ProcessAreas(Project project) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 600
   at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.PrepareDataToRender(TextTransformation tt) in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 557
   at Microsoft.VisualStudio.TextTemplating3FE65EE761BB32C4AE5AEEB1949A6FC143551E0A56C74E6B36511A416E2DE40FB92F7CB1BC6FC7A97FF5B622AE39377BBFB9463480555898ADB8DD6D286C533D.GeneratedTextTransformation.TransformText() in c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt:line 40    WebApplication3 c:\dev\MyApp\WebApplication3\src\WebApplication3\T4MVC.tt   1398

还有其他建议吗?

另请参阅与此有关在ASP.NET中替代T4MVC的问题5.

See also this related question about alternatives to T4MVC in ASP.NET 5.

推荐答案

在这一点上,T4MVC并未设计为在ASP.NET 5项目上运行,因此我对此并不感到惊讶.

At this point, T4MVC is not designed to run on ASP.NET 5 projects, so I'm not surprised that it doesn't work.

前一段时间,使用基于Roslyn的方法启动了一个单独的 R4MVC 项目.但是,这是在ASP.NET 5不支持T4的时候完成的,现在已经重新考虑了.

A while back, a separate R4MVC project was started, using a Roslyn based approach. However, this was done at a time when there was no T4 support with ASP.NET 5, and that has now been revisited.

因此,可能会有希望在该平台上运行T4MVC,但是有人需要花费时间来查看它的工作距离.

So it's possible that there is hope to get T4MVC running on there, but someone would need to invest the time to see how far it is from working.

我只是迈出了很小的一步,并且已修复您击中的空引用(不是尚未发布,则需要手动修复).但是,然后我碰到了一个似乎完全可以拿到手的情况.

I just took a tiny step and fixed the null ref that you hit (not yet released, you'll need to hand fix). However, I then hit a condition where it seems to hand altogether.

无论如何,这不是一个全面调查所有问题的地方,但是如果有人愿意接受,我们可以在 https://github.com/T4MVC/T4MVC .

Anyway, this is not the place to fully investigate all issues, but if someone wants to take that on, we can discuss on https://github.com/T4MVC/T4MVC.

这篇关于使T4MVC与ASP.NET 5一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 04:38