Here's a Visual Studio macro to help.
What is he doing
Now you are probably using T4MVC links in such places:
- Layout = MVC.Shared.Views.MasterSiteTheme;
- ScriptManager.AddResource (Links.Content.Script.jQueryXYZ_js);
- <link type = "text / css" href = "@ Links.Content.Style.SiteTheme_css" />
- return View (MVC.Account.Views.SignIn);
- @ Html.Partial (MVC.Common.Views.ContextNavigationTree)
- @ Html.ActionLink ("Login / Register", MVC.Account.SignIn ())
F12 (Go to Definition) already works for the last bullet (action), but this hack is designed to cover other scenarios (resources).
Macro
Imports EnvDTE Imports System.IO Public Module NavT4Link Sub NavigateToLink() DTE.ExecuteCommand("Edit.GoToDefinition") Dim navpath As String = Path.GetFileName(DTE.ActiveDocument.FullName) Dim isContentLink As Boolean = navpath.Equals("T4MVC.cs") If (isContentLink Or navpath.EndsWith("Controller.generated.cs")) Then Dim t4doc As TextDocument = DTE.ActiveDocument.Object() navpath = CurrentLinePathConstant(t4doc) If isContentLink Then t4doc.Selection.MoveToPoint(t4doc.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass).StartPoint) t4doc.Selection.FindText("URLPATH") navpath = Path.Combine(CurrentLinePathConstant(t4doc), navpath) End If If navpath.StartsWith("~") Then DTE.ActiveDocument.Close(vsSaveChanges.vsSaveChangesPrompt) Dim proj As Object = DTE.Solution.FindProjectItem(DTE.ActiveDocument.FullName).ContainingProject navpath = Path.GetDirectoryName(proj.Fullname()) + navpath.TrimStart("~") DTE.ItemOperations.OpenFile(navpath) End If End If End Sub Function CurrentLinePathConstant(ByVal t4doc As TextDocument) As String t4doc.Selection.SelectLine() Dim sa() As String = t4doc.Selection.Text().Split("""") If sa.Length > 1 Then Return sa(sa.Length - 2) Else Return "" End Function End Module
Installation
- In Visual Studio, press "Alt-F8" to open Macro Explorer.
- Right-click My Macros, select New Module ..., and click Add.
- Replace all text with the code shown here.
- Save and exit the macro editor.
- Open "Tools: Options."
- In the left pane, select "Environment: Keyboard."
- In the "Show commands containing" text box, enter "T4."
- In the "Press shortcut keys:" field, press the "F12" key.
- Click Assign and OK.
In unencrypted VS, this installation process does not lead to the creation of a βbindingβ macro. The workaround was to (CTRL-SHIFT-RR) write an empty macro and paste the code into it without renaming it. If someone knows a more documented approach to installing a macro in VS, please comment.
Notes / Cautions
This means replacing the current F12 functionality, so if it is not a T4MVC link, it will do the usual, otherwise it will continue to open the resource. It handles most cases, but not empty T4MVC pool controller methods. Those you dumped in the same place as before.
For Content / Asset / Link resources, for example, for navigating through them in the solution explorer, perhaps for image files, but I did not see this functionality in Visual Studio documents.
source share