I don't have ReSharper at my current gig, and I miss the "Extract Variable" refactoring. I understand that it's possible to write your own refactoring "snippet" in VS. Does anybody have one that does this?
2 Answers
In Visual Studio 2017, if you select something, on right-click you will find a menu option "Quick Actions and Refactorings", with shortcut ctrl+..
This seems to be somewhat similar to ReSharper's ALT+Enter.
This allows you to extract a variable, as in this example where the text was selected and then ctrl+. was pressed:

- 6,219
- 3
- 39
- 63
-
Is this VS2017 Enterprise? I don't see this option in the Professional version – Kentative Jun 18 '17 at 03:23
-
2works in my VS2017 Enterprise, although it takes ~1min to calculate it... a bit shameful, as for resharper it's 1s in the same project – mikus Sep 19 '17 at 11:05
-
@Kentative Professional. But you must select the text that you want to extract a variable from. – ANeves Sep 20 '17 at 11:23
-
works for VS2017 Professional as well. Why `Ctrl+.` though and not `Alt+Enter`...? `Alt+Enter` is already used on VS2017 for fix suggestions. – yair Feb 13 '18 at 11:36
Have a look at this post, but it does not seem to be a documented feature:
Snippets For Refactoring
Browse to your "Program Files\Microsoft Visual Studio 8\VC#\Snippets\language id\Refactoring" directory and you'll find the snippets used to perform the refactoring techniques in the Refactor menu. (...) If you're going to try modifying these snippets then (...)
Another way would be a write a macro using the EnvDTE programming model. Not easy, but should be feasible.
-
I can't find the snippet for extracting a variable. Could you name it in your answer? – ANeves Nov 17 '22 at 11:54
-
The original question, as I understood it, is "how to create snippets". These files are in a directory called Refactoring, but they seem to let us add a piece of code, rather than change existing code. At the time of the question, I guess the only complete answer is to write a macro. As of today, your answer is better. – Timores Nov 19 '22 at 18:16