If you can not extract method - here is a solution!

Any Idea how to extract method?

I simply don’t see related text in RMB menu.

Thanks!

1 Like

Hi,

Select the text you want to refactor, and then click on “Quick Actions and Refactorings”, you will then be given an option to “Extract Method” to the left of this context menu.

image

I think the issue may be what you have selected (or rather, not selected). For instance, if you make your selection the entire if/else statement, brackets and all, then right-click… do you get the extract method option?

EDIT - Derp, looks like I got to your question at the same time as Rob :slight_smile:

1 Like

Synchronised awesomeness :slight_smile:

1 Like

No… no any sign of possibility to extract.
If there is any hint how get it from upper menu?

By the way.
Hardware: i7, 16 gb, 960M
Software Win 10 64bit,

Are you selecting the code within an existing method before right-clicking?

Yes. I mean clicking ‘Quick Actions and Refactorings’ does not lead to any result. Like it simply does not work.

Any chance you can record a short video of the issue and upload it?

Yes, Rob, here it is

hmmm, quite odd…

Some things to try below, in order of severity, but please make a backup of your work before trying them;


  • Close all files
  • Under Solution Explorer, right-click on the Solution and choose Clean solution
  • Repeat, and choose Rebuild solution
  • Close Visual Studio
  • Re-open Visual Studio by double-clicking on a script within Unity
  • Re-test the Extract Method functionality

  • Close all open files and then Visual Studio
  • Re-open Visual Studio
  • Click Tools / Options / Debugging / Symbols / Empty Symbol Cache
    image
  • Close Visual Studio
  • Re-open Visual Studio by double-clicking on a script within Unity
  • Re-test the Extract Method functionality

  • Close Visual Studio
  • Open Console and navigate to Visual installation folder, on my PC this is C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE
  • run devenv.exe /resetsettings
  • Visual Studio will now launch, it may take longer to launch than normal
  • Close Visual Studio
  • Re-open Visual Studio by double-clicking on a script file from within Unity
  • Re-test the Extract Method functionality

Did any of the above help?

I never saw the entire switch statement selected… the video ends before that… you can’t refactor anything less than a complete statement.

all the results are same, JackDraak, even if the whole statement in case :slight_smile:

Rob, thank you! Will try to do it during the day… well if the work traffic lets me get a window. If not, that plan moves to evening, Thank you for detailed instructions!

1 Like

No problem, hope one of these works.

My feeling is that Visual Studio has got itself a little confused with the symbols, as such, what you select and what it thinks is selected are possibly not the same. I think the dialogue window you see that mentions about the caret position is an indication of this. Regarding the Quick Actions and Refactorings, if you look at the bottom left of the screen, on the blue bar it advises you that “No quick actions are available here” - it states this all the way through your video, regardless of what you select.

I’m hoping the more straightforward cleaning/rebuilding approach will resolve this but if not, the other two approaches may work.

Just as a little note on the /resetuserdata, this is a little more destructive and will affect any IDE configuration you’ve made, including plugins, you may want to read up on this specifically before trying it.

I was about to provide you a link but discovered that the above was for the 2015 version of Visual Studio, the parameter to use is actually, /resetsettings, as such, I’ve updated my earlier post and there’s a link below for you.


See also;

Rob I tried 2 methods. But there is one that is not clear. I need screen to screen instructions.
Please understand, I’m not very skilled computer user. I spent some time to recall how to run ‘RUN’ and there run ‘cmd’ and from the 3rd attempt I recalled command cd.

So here is solution that I can not perform.

  • Close all files
  • Under Solution Explorer, right-click on the Solution and choose Clean solution
  • Repeat, and choose Rebuild solution
  • Close Visual Studio
  • Re-open Visual Studio by double-clicking on a script within Unity
  • Re-test the Extract Method functionality

The problem is on stage of 2nd dot.

I found ‘Solution Explorer’ with no problem.
But where to click RMB and choose ‘Clean solution’?

Thank you.

I found alternative way to settle.

Thank you all, guys!

1 Like

Hi,

You need to right click on the actual solution itself, the context menu then displays options to both Clean and Rebuild. Cleaning clears all of the temporary and cached files that are generated, so if any of the debugging information has become corrupted, this is a good way to get rid of it.

Here’s a little video showing how to do it. At the start I show how to view the solution as opposed to the directory in which the solution lives. I’ve only recorded the corner of the screen, but if you watch the console when you first Clean and subsequently Rebuild you will see it outputs some information and tells you whether it was successful or not.

Glad you have got this working, although the other menu should launch the same process, rather than you having to add a specific button yourself. Perhaps the issue has cleared and if you try the original method again it will work?

Will try but seems it does not work… only in matter I discovered, Thanks, Rob! Keep going ahead!

That seems quite strange.

Does the keyboard short-cut work if you use that, I think its CTRL + M?

Privacy & Terms