Scott Hanselman

VS Refactoring Essentials (formerly) NR6Pack - Free analyzers and refactoring for Visual Studio 2015

July 08, 2015 Comment on this post [24] Posted in Open Source | VS2015
Sponsored By

There are some amazing free and open source C# and VB.NET analyzers and refactorings that you can download and use now in Visual Studio 2015. Formerly called "NR6Pack" they have now be renamed VS Refactoring Essentials, a nice nod to VSWebEssentials I must say.

The best part, of course, is that since the Visual Studio Community Edition is not only FREE but also now supports extensions, that any open source or indie developer can get pack some serious power into their Visual Studio installations.

There's some interesting history here as the project and its core technology has been around for a while. It's moved from SharpDevelop into NRefactory, then NRPack, and now with the major Roslyn refactor by Mike Krüger, you've got a nice Roslyn code-base and a free extension for all called VS Refactoring Essentials.

There's lots of great refactorings, too many to include screenshots for all of them, but here's a few favorites.

Sometimes you'll dig deep into a dictionary without being defensive. VS Refactoring Essentials will notice and check the dictionary key first. Note that you'll always get a preview of what it's going to change first!

CheckDictionaryKeyValueCodeRefactoring

Conditionals can sometimes get away from you. VS Refactoring Essentials will simplify common conditionals and make them easier to read.

SimplifyConditionalTernaryExpressionAnalyzer

When setting boolean flags you'll sometimes set it, check something, and update that same flag. This refactoring will notice that and do it all on one line for you.

ConvertIfToOrExpressionAnalyzer

I never get ?: and ?? correct. VS Refactoring Essentials will help you move between ternary operators and null coalescing.

ConvertConditionalTernaryToNullCoalescingAnalyzer

FYI - This is a purely open source project that is not affiliated with Microsoft. It's part of the SharpDevelop OSS project and is MIT-licensed. Big thanks to the SharpDevelop team!

NOTE: Visual Studio 2015 will launch on July 20th. Be sure to download Visual Studio 2015 Community on that date. Until then, the V2015RC of Community is here.

Be sure to follow @VSRefactoring on twitter and thanks for them for their hard work and community focus! Go download Refactoring Essentials here for VS2015. Report issues on their GitHub.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
July 08, 2015 4:36
Great stuff Scott.

But I feel like you should also mention this project as well.


https://github.com/DotNetAnalyzers

The Style Cop ones are especially nice since the ReSharper StyleCop plugin has never been open sourced by the maintainer.
July 08, 2015 4:50
There's also the Code-Cracker project, it has over 90 analyzers/code fixes and it is a very well maintained open-source project.
July 08, 2015 10:07
Great tips, thanks you two!
July 08, 2015 12:37
Nice! How does this compare to ReSharper?
July 08, 2015 13:05
I also tested VS2015 Community edition. But the very first thing I was missing was "Refactor / Extract method". I didn't find it on the web page, but Refactoring Essentials can also do Extract Method.
This is the most important feature IMHO as this was the reason why I went ahead to VS Professional right away.
July 08, 2015 13:14
Great stuff, Are there any versions of this available for VS 2013?
July 08, 2015 14:44
Thanks Scott!
July 08, 2015 18:45
Thanks Scott.
Community Edition is SO AWESOME (saves me from the VS2015 "msdn required" apocalypse). I will however stick to CodeRush from Developer Express.
July 08, 2015 19:05
The support for Visual Basic appears to be rather limited. Hopefully they'll add more features in the future.
July 08, 2015 20:02
Thanks for the tips !

CodeMaid is also a nice and free extension for refactoring and code analysis. I've been using it for several months and I'm quite happy with it.
July 09, 2015 6:55
Thank you Scott for the tips.
July 09, 2015 12:45
Thanks mate for such tips. I absolutely loved it.

whatsapp plus download
July 09, 2015 19:27
As far as I've seen it yet VS15 in combination with Extensions like this have a lot of resharpers functionality. I hate resharper as it does way to much and is slow. Customizing its config until it works as i wish means disabling like 90% of its features, especially in everything except C#.

Any experience if this could really replace resharper?
Are there any very good reasons to stay on resharper?
Max
July 10, 2015 2:04
Any Visual Basic 6.0 news ?!! a lot of people are asking for this ...
July 11, 2015 16:38
O.T. : And about "parent", "kids", "family" and so on... any news about Family Safety for Visual Studio 2015?
July 12, 2015 18:07
One of the things I love about Resharper is that it helps a team have a consistent style and naming convention, e.g.:


private _myPrivateField;

public void MyPascalCaseMethod()

Does this do the same?
Thanks

July 15, 2015 0:36
I could be totally wrong (not the first time), but in regards to example 2: I've always heard it harped on that you should make code that is understandable to the user. It seems like that one may need to have a comment added as to what that optimization is doing as it may not be immediately understood by someone looking at the code.

In the case of 3, would o != 10 be worse for the compiler than o < 10 || o > 10 (either way, that's a really cool intent deciphering bit of code)?

That ?? vs ? one would probably run roughshod over my code over various projects at work. Honestly, didn't know about ?? but I've used that same style of check all over the place. Nice to know, thanks.
July 16, 2015 17:08
The `ContainsKey` refactoring has some issues, which I submitted to the project:
https://github.com/icsharpcode/RefactoringEssentials/issues/26

1. The result isn't DRY. The key is repeated in the `ContainsKey` call and the call to the dictionary indexer. This opens the door to bugs if one instance of the key is changed but not the other. Additionally, the cost of evaluating the key is doubled, which may be significant if not a simple literal.

2. Two dictionary lookup are required. Instead, the refactoring should generate `TryGetValue`.

3. The refactored code assumes that the proper response to a missing key is to do nothing. Somethings this is correct, but often not. Just as generated code for methods includes `throw new NotImplementedException()`, this refactoring should include code to throw an exception, which the user can replace with the appropriate handling logic or remove as appropriate.
July 17, 2015 14:05
@Jason Steele - There's a way for you to find out!
@Marina - We want VB 7.0 !
@Niklas - I'm glad this will probably kill off re-sharper, I don't like it for a myriad of reasons:
1. Expensive.
2. Need to re-purchase for each version of VS.
3. Developers develop a perceived dependence on it - ie they think they can't code without it.
4. Generally - I've not found it useful, I've seen it duplicate code all over a project (the Nullable<T> routine it seems to add to every controller).
5. Developers mostly don't understand it, it just makes their code look a bit more "pro" where pro = slightly unreadable.
6. Refactoring tools should support, not take control.
@Robert - Agreed, maybe a textbox explaining the change would be of massive help.
@Max - I hear you partner!
@Edward Brey - you've submitted it to their github, you don't need to advertise here.

Peace.
July 18, 2015 16:04
@Will, it is worthwhile to highlight the issues here. Even though the library is being fixed, the post teaches more than just about a library. Refactoring examples implicitly teach about how to write code. Some people could walk away with the idea that this is a good use of `ContainsKey`. A clarifying note here to help people think about how to write better code helps everyone.
July 19, 2015 2:40
I, too, am a diabetic C# developer. We need a t-shirt: "Diabetics write the sweetest code."
August 05, 2015 17:44
I have gathered a collection of great Roslyn packages.
August 11, 2015 14:40
@Anders somehow the collection link got messed up: it should be this one http://www.lybecker.com/blog/2015/08/05/dotnet-compiler-platform-roslyn-analyzer-packages/
August 17, 2015 5:45
Visual Smarter is another one. It provides more than 200 refactoring tools/coders/widgets already. And the number is still going up.

VisualSmarter.blogspot.com

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.