Apply Visual Studio Quick Actions and Refactorings across entire C# solution
Asked Answered
R

2

5

I am trying to cleanup/refactor a legacy C# solution and am therefore exploring options how certain refactorings or quick actions could be applied for the entire solution.

For example, Visual Studio 2017 offers 'Replace xxx and xxx with property' and 'Use auto-property' actions, which I can apply via the lightbulb icon for individual classes and methods/properties.

How could I apply these to the entire application or semi-automatically iterate all occurrences (300+) and apply these? I am open for all options - command line, powershell, VBA, even VISX-development. I do not want to re-develop the refactoring itself and I don't think that a simple find&replace will do either.

Reciprocal answered 27/3, 2019 at 15:53 Comment(0)
E
6

When the quick action window is visible, you can apply the selected fix to the single instance, or across the entire document/project/solution: Quick action window -> Apply to Solution

If you apply each identified fix across your solution (or project) then you should only need to process each suggestion once, as the first one you change will apply to all further instances.

Alternatively, you could use the dotnet Format tool to apply a set of specific formatting rules to your project via the command line, although this depends upon you having an editorConfig file with your rules defined.

Eteocles answered 19/11, 2019 at 11:7 Comment(0)
G
0

Have a look at the EditorConfig. What you're looking for is the Language Conventions topic and you can flag an action as silent (synonym for refactoring in v15.8):

# $slnRoot\.editorconfig

[*.cs]
dotnet_style_prefer_auto_properties = true:silent

Then when you run across that action in your code, you can apply the quick action to your entire solution, file, project, etc.


Note: there have been some bugs with EditorConfig in VS2017. I've had to close the solution and restart the IDE to get changes to take sometimes.

Gerena answered 17/9, 2019 at 13:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.