Wednesday, August 22, 2012 7:23 PMWe had some macros in VS2010 that would perform functions like auto-commenting a method or collapsing all of the items in the solution explorer. We had those hooked up to shortcut keys. I assume we would need to create an add-in in VS2012 to achieve the same thing. Are there any examples of creating an add-in with a shortcut key assignment?
Wednesday, August 22, 2012 7:46 PMModerator
It would be better to use a package over an AddIn. AddIns don't have static decleration of commands and thus have to either be eagerly loaded to provide the commands or have to have already been run at least once so the commands are already known to the system. Also dynamically added commands don't have a great keybinding story, you can change them via Command.Bindings, but it is a bit of a hack since on localized installs of VS you need to provide the loc-equivalent strings for things like 'Alt', 'Control', etc... and these aren't exposed by VS in any way. I filed a bug on this internally and it was closed as Won't Fix :(
I would recommend making a package, adding a few commands via VSCT isn't that hard, there are numerous examples of how to do it, and you get the benefit of delay loading and all around better integration into VS.
- Marked As Answer by Ego JiangMicrosoft Contingent Staff, Moderator Friday, August 31, 2012 9:34 AM
Thursday, August 23, 2012 2:01 AM
Thanks for the pointer. Seems like a complicated route to achieve the same result as the old macros in VS2010.
Very disappointed that they stripped that stuff out of VS2012 - the functionality was already there and useful even if only a small % of devs used the tools - why rip them out?
Thursday, August 23, 2012 2:25 AM
Hmmm...downloaded the SDK and created a VS Package project as per this page:
I went through the steps for the wizard and selected C# language but when I run this project using F%, I get an exception "Cannot find the requested resource". I hit continue and an instance of the IDE loads with my command listed under Tools.
Not sure there this exception is coming from though - any ideas?
Call stack:Microsoft.VisualStudio.CommonIDE.dll!Microsoft.VisualStudio.CommonIDE.ResourceLoader.TryEachApplicableNamespace<byte>(string resourceName, Microsoft.VisualStudio.CommonIDE.ResourceLoader.GetResourceDelegate<byte> getResource)
Microsoft.VisualStudio.CommonIDE.dll!Microsoft.VisualStudio.CommonIDE.ResourceLoader.FindResource<byte>(string resourceName, int lcid, System.Func<object,byte> fnConvert)
Microsoft.VisualStudio.CommonIDE.dll!Microsoft.VisualStudio.CommonIDE.ResourceLoader.GetBlob(string resourceName, int lcid, out byte bytes, ref int count)
[Native to Managed Transition]
Thursday, August 23, 2012 3:01 AMModerator
Support cost + small number of users. It wasn't simply leaving the code in place, new features had to be macro recording aware and there were always bugs being fixed. A package is more heavyweight than a macro to be sure, but the integration/perf is also much, much better.
Friday, August 24, 2012 6:05 AMGot the VSPackage stuff working after quite a bit of rummaging around. It's certainly a lot more complicated than macros in VS2010, especially as my use case was really quite trivial. I found the documentation quite fragmented and lacking an overview that would have helped me understand what I was doing. I might have just been looking in the wrong places mind you!
Monday, August 27, 2012 9:36 AM
I think macro is easier to create and use.
Monday, August 27, 2012 11:30 PMAh...yes of that there is no doubt, but macros no longer exist in VS2012.
Friday, August 31, 2012 9:34 AMModerator
I marked Ryan's reply as answer.
If you feel it is not the answer, please unmark it.
Thank you for your understanding and support.
MSDN Community Support | Feedback to us