16

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 :-)

Christian Ruppert
  • 3,749
  • 5
  • 47
  • 72

4 Answers4

9

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    Thanks, I just tried the AddIn project, and so far "I like it". I think it is worth looking into, seems to support the same basic stuff like macros. A little bit more complex, but hey, likely more powerful too. Macros are still nice to "see" the VB solution, and copy it into the AddIn Code... – Christian Ruppert Sep 18 '09 at 00:26
4

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!

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
  • 2
    What a shame :-) Ok, now I have to get my calculator and check "time saved per macro > time to learn VB"... VS 2010 also only VB? – Christian Ruppert Sep 18 '09 at 00:06
  • 2
    Went the other way :-) Think I will start to write AddIns instead of Macros. Can do the same in C#, if not more. (and it's really a "habit thing" - PHP and C# must be enough. btw I am an engineer with programming skills, so I try to do as few languages as possible, but these decent enough to be productive) – Christian Ruppert Sep 18 '09 at 00:29
3

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

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66
0

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.

  • 2
    And since you have ReSharper, you can use ReSharper's Live Templates. These are much more powerful than VS snippets. – TrueWill Sep 18 '09 at 01:26
  • Yes, but the whole snippet thing is a different issue. I want to collapse items in the solution explorer, automate unit tests or change from design view to code view. All stuff way beyond snippets (at least how I understood them)... – Christian Ruppert Sep 18 '09 at 01:52
  • @Christian: Fair enough, but running unit tests can be done with ReSharper and changing from design to code view is a hotkey in Visual Studio. Collapse in Solution Explorer is in either ReSharper or one of the plugins (Agent Smith or Johnson). I think I've written one macro in the last year, after which ReSharper came out with a new feature that made it obsolete. ;) – TrueWill Sep 18 '09 at 02:58