C# for writing macros in Visual Studio?

2019-01-22 21:06发布

问题:

I started C# a while ago and really like it.

I work with VS 2008 and really like it.

I tried Resharper and loved it.

Now I am starting with Macros in VS2008 to increase my coding speed a little more. And stumble upon visual basic. And I do not like that.

Is there any way to write macros in C#. Or a workaround, in writing a plugin for VS to reach the same goal. Just let me stress out, its a productivity issue. I just want to automate some features I use often (create macro, assign shortcut, tell my touchscreen-app to send this shortcut)...

So from an experts point of view, is there an easy way to e.g. "collapse all items in the solution explorer, but expand all starting with the letter A" (just a silly example) without using visual basic?

Thanks for any tips, Chris

PS: I was nearly happy with recording and playback. But, as it turns out, some "external" resharper command (like collapse all) do not play well with macros (getting strange com errors). So I thought, hey, a loop to collapse all items, I can do that. But unfortunately not really quick in VB :-)

回答1:

Try writing a DLL in C# and referencing it in a VB macro.

This way, the only VB you'll need to write is the code to connect the DLL to the IDE.



回答2:

Unfortunately no, Visual Studio only supports VB.NET for macros.

I wouldn't stress too much about not having C# for macros (many C# developers seem mortified that VB.NET code will stick to their shoe like toilet paper). Rather take pride in your ability to be productive in multiple languages!



回答3:

Visual Commander (developed by me) lets you write Visual Studio 2010+ (macro) commands in C#.



回答4:

Snippets are the closest which I've come across. Snippet Editor 2.1 does a pretty good job setting them up without to much hassle.