89

I am having trouble finding the right-click context menu in Visual Studio 2015. I know that nothing is wrong with my project or the file I am working. I can find the right-click context refactor menu in Visual Studio 2013. However, in Visual Studio 2015 there isn't a refactor context menu in the right-click context menu.

Where did it go? How do I get it back?

Your suggestion cannot include menu EditRefactor.

I have tried to reset my Visual Studio settings back to default using menu ToolsImport and Export Settings and that didn't bring the menu back either.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mr. Young
  • 2,364
  • 3
  • 25
  • 41

5 Answers5

95

Some of the refactoring tools have been relocated or are at least accessible in a different manner than they were previously.

Using the extract method refactor as an example, you can still use this function; it is just not done the same as before:

Select parts to extract

Right click

Right click

Quick actions

Quick actions

Click extract Method

Click extract method

I think they've changed it to feel more "ReSharper"ey. All of the functionality should still be there however.

Here's more information on refactoring in Visual Studio 2015 - hopefully this helps! Refactoring (C#)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kritner
  • 13,557
  • 10
  • 46
  • 72
  • yeah, it'll take some getting used to for sure. I'd bet that it's more intuitive for regular users of resharper though... maybe... – Kritner Jul 24 '15 at 16:30
  • 2
    Thank you for the screenshots. I am not sure I would had found where this was moved otherwise! :-) – Mr. Young Aug 01 '15 at 23:11
  • 1
    FYI: There appears to be a bug in some version of VS around this functionality [VS crashes upon refactoring some code to extract a new method](https://github.com/dotnet/roslyn/issues/4251) – Liam Sep 08 '15 at 12:19
  • 2
    Nice explanation. + I'm a sucker for pretty pictures :) – Fetchez la vache Sep 17 '15 at 09:43
  • 1
    Extract method is not showing up on my VS 2015. Any ideas why? – Bartho Bernsmann Mar 01 '16 at 14:55
  • 1
    @BarthoBernsmann it's context specific, are you sure you have a valid bit of code within a method highlighted for extraction? – Kritner Mar 02 '16 at 13:59
  • I think there was something related to the project I was working on, because I was able to Extract method as suggested on another project. Thank you! – Bartho Bernsmann Mar 02 '16 at 14:40
  • Screens shots are not low-vision friendly. – Darrel Lee Jun 26 '16 at 09:06
  • @DarrelLee have you clicked them? I'm about as bad vision as you can get (20/400+ w/o glasses) and can see them no problem when not looking at the thumbnail – Kritner Jun 26 '16 at 13:05
  • No, I didn't click them. Tried scaling in the browser. thanks. – Darrel Lee Jun 26 '16 at 23:53
  • It is possible do it from keyboard (without mouse) which is generally faster way - select block (shift + arrow), show quick actions and refactoring (ctrl + .), optionally select item (arrow) and confirm item (enter). – honzakuzel1989 Sep 21 '16 at 16:19
  • this answer applies to Visual Studio 2017, too – bkwdesign Apr 27 '17 at 11:53
2

You no longer need to access the refactoring using the mouse right click.

It is recommended that you use the keyboard shortcut keys within Visual Studio.

For all possible shortcut keys, see Default Keyboard Shortcuts in Visual Studio, Refactor.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashraf Sada
  • 4,527
  • 2
  • 44
  • 48
  • 1
    The given link goes to a page for Visual Studio 2008. A list for V.S. 2015 is at https://msdn.microsoft.com/en-us/library/da5kh0wa.aspx#bkmk_refactor. – Mike Grove aka Theophilus Dec 06 '17 at 18:30
  • 1
    Short version: CTRL+R,M. Also, Edit > Refactor > Extract Method... (only visible when a code block is highlighted). – Chris Mar 07 '18 at 15:35
2

You might need to build the project to get it to work.

See Code Editing ASP.NET Web Forms in Visual Studio 2013 | Microsoft Docs. (If it is missing then the point is that I am using an example provided by Microsoft.). In Refactoring and Renaming see To extract a method in a C# page. When I follow the instructions I cannot find the feature to extract the code to a method. When I tried the Edit menu it said I did not have valid code. Then I built the project and the feature to extract the code was available and worked.

Sam Hobbs
  • 2,594
  • 3
  • 21
  • 32
0

If you change the name of the object you are refactoring, the light bulb then appears to the left which asks if you wish to change the name of the object (i.e. refactor) or generate a new constructor for the new named object.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dave
  • 11
0

Ctrl + . is the shortcut key for extracting a method in Visual Studio 2015 and onward.

Ctrl+M, R does not work anymore in new versions.

Mr. Young
  • 2,364
  • 3
  • 25
  • 41