curlysemi / R4Mvc5

R4MVC5 is a Roslyn code generator for ASP.NET MVC5 apps that creates strongly typed helpers that eliminate the use of literal strings in many places
Apache License 2.0
1 stars 0 forks source link
msbuild mvc5 r4mvc roslyn t4mvc

R4Mvc5

R4Mvc5 is a Roslyn based code generator for ASP.NET MVC 5 apps that creates strongly typed helpers that eliminate the use of literal strings in many places.

It is a modification of R4MVC (re-implementation of T4MVC for ASP.NET Core projects) to support MVC5. (This is to allow regeneration of the helpers outside of Visual Studio.)

Benefits

Instead of

@Html.ActionLink("Dinner Details", "Details", "Dinners", new { id = Model.DinnerID }, null)

R4MVC lets you write

@Html.ActionLink("Dinner Details", MVC.Dinners.Details(Model.DinnerID))

and that's just the beginning!

Benefits of R4Mvc5 over T4MVC

While T4MVC is probably more stable and better maintained, it is implemented in T4 templates that rely on the DTE interface, meaning it can't work outside of VisualStudio, which means you can't use T4MVC.tt with Release Manager and have to track all the .generated.cs files. R4Mvc5 can work with Release Manager!

As far as getting this to work with Release Manager for TFS, VSTS, Azure DevOps, or whatever Microsoft has decided to call it, the strategy we're using is to track the EXE and all dependencies in the repo, and have prebuild events for all MVC projects that invokes the EXE. (This gives us the flexibility to patch R4Mvc5 as needed.)

Example

(Assuming you're in a shell while in this repo's directory)

.\src\R4Mvc.Tools\bin\Debug\net461\R4Mvc5.exe generate -p 'C:\Users\Me\Code\SomeMvc5Project\SomeMvc5Project.csproj'

You should see some output like the following:


  R4Mvc5 Generator Tool v1.0.0

Using: Visual Studio Professional 2017 - 15.8.28010.2048
Project: C:\Users\Me\Code\SomeMvc5Project\SomeMvc5Project.csproj

Creating Workspace ...
Loading project ...
Compiling project ...
Detected MVC version: 5.2.4.0

Processing controller SomeMvc5Project.Controllers.HomeController
Processing controller SomeMvc5Project.Controllers.UserController

Generating \HomeController.generated.cs
Generating \UserController.generated.cs
Generating \SharedController.generated.cs
Generating \T4MVC.cs

Operation completed in 00:00:05.0435271

Migrating From T4MVC

Here are some loose instructions for how to replace T4MVC for a project called 'MyLameProject':