公司开发的项目使用的是Mvc框架,且Js与View页面是分开在两个文件夹下的,所以如果在View页面转到Js页面或者反过来都要先找到页面打开,很不方便.于是我做了一个VS外接程序可以很方便的用快捷键就直接互相跳转.
公司网站目录是如下图所示:View目录有Js分别在两个文件夹下:Views与Scripts




Command command = commands.AddNamedCommand2(_addInInstance, "MyAddinJSView", "JSView互跳", "JSView互跳", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (commandName == "MyAddinJSView.Connect.MyAddinJSView") { handled = true; try { var file = _applicationObject.ActiveDocument; string opFile = string.Empty; if (file.FullName.ToLower().EndsWith(".cshtml")) { opFile = file.FullName.ToLower().Replace(@"\views\", @"\scripts\").Replace(".cshtml", ".js"); } else if (file.FullName.ToLower().EndsWith(".js")) { opFile = file.FullName.ToLower().Replace(@"\scripts\", @"\views\").Replace(".js", ".cshtml"); } if (!string.IsNullOrEmpty(opFile)) { _applicationObject.ItemOperations.OpenFile(opFile); } } catch (Exception) { } return; } } }


Visual Studio中View页面与Js页面用快捷键互相跳转
原文:http://www.cnblogs.com/liningit/p/MyAddinJSView.html