Make T4MVC work with ASP.NET 5
Asked Answered
E

2

7

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.

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).

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

Here's what I've tried:

  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:

Error NU1002 The dependency T4MVCExtensions 3.16.5 in project WebApplication1 does not support framework DNXCore,Version=v5.0.

  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....

enter image description here

... 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    

Any other suggestions?

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

Endurant answered 21/12, 2015 at 16:13 Comment(3)
First thing, t4 files are classified as content and nuget won't import them in your project anymore. Same for js or css. That solves your first mystery.Leto
Then, there is the .NET Core things. That might be 100% justified and to have it "compatible" with .NET Core, you need to be explicit when creating your package that you support it. I don't know if T4MVC supports it.Leto
Finally, David Ebbo is the guy who wrote the package. He's a Microsoft Employee and I'll try to have him see this thread. :)Leto
D
2

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

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.

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.

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.

Duprey answered 21/12, 2015 at 23:11 Comment(0)
F
3

As David Ebbo (hey!) pointed out, R4MVC - a side project was started a long time ago, but was stalled due to (at the time) breaking changes in the Roslyn compiler.

Luckily, the project was revived, and R4MVC has just released it's first alpha build, with more changes coming soon.

While the project works somewhat differently, and isn't using t4 templates, the end result is the same, and we're working to achieve feature parity with T4MVC in the near future.

Flit answered 11/8, 2017 at 10:2 Comment(0)
D
2

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

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.

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.

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.

Duprey answered 21/12, 2015 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.