Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make T4MVC work with 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.

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.

like image 670
Max Avatar asked Dec 21 '15 16:12

Max


1 Answers

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.

like image 68
Artiom Chilaru Avatar answered Nov 20 '22 23:11

Artiom Chilaru