Scott Hanselman

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

July 8, '15 Comments [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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Wednesday, 08 July 2015 00:36:41 UTC
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.
Issa Fram
Wednesday, 08 July 2015 00:50:15 UTC
There's also the Code-Cracker project, it has over 90 analyzers/code fixes and it is a very well maintained open-source project.
Wednesday, 08 July 2015 06:07:48 UTC
Great tips, thanks you two!
Scott Hanselman
Wednesday, 08 July 2015 08:37:53 UTC
Nice! How does this compare to ReSharper?
Niklas
Wednesday, 08 July 2015 09:05:12 UTC
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.
Wednesday, 08 July 2015 09:14:02 UTC
Great stuff, Are there any versions of this available for VS 2013?
Carl
Wednesday, 08 July 2015 10:44:27 UTC
Thanks Scott!
Tom Alderman
Wednesday, 08 July 2015 14:45:46 UTC
Thanks Scott.
Community Edition is SO AWESOME (saves me from the VS2015 "msdn required" apocalypse). I will however stick to CodeRush from Developer Express.
James Makumbi
Wednesday, 08 July 2015 15:05:35 UTC
The support for Visual Basic appears to be rather limited. Hopefully they'll add more features in the future.
Bill Hoelzer
Wednesday, 08 July 2015 16:02:38 UTC
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.
Loïc Lopes
Thursday, 09 July 2015 02:55:15 UTC
Thank you Scott for the tips.
Thursday, 09 July 2015 08:45:44 UTC
Thanks mate for such tips. I absolutely loved it.

whatsapp plus download
aman
Thursday, 09 July 2015 15:27:45 UTC
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
Thursday, 09 July 2015 22:04:36 UTC
Any Visual Basic 6.0 news ?!! a lot of people are asking for this ...
Marina
Saturday, 11 July 2015 12:38:15 UTC
O.T. : And about "parent", "kids", "family" and so on... any news about Family Safety for Visual Studio 2015?
Sunday, 12 July 2015 14:07:46 UTC
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

Jason Steele
Tuesday, 14 July 2015 20:36:45 UTC
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.
Robert
Thursday, 16 July 2015 13:08:04 UTC
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.
Friday, 17 July 2015 10:05:01 UTC
@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.
Will
Saturday, 18 July 2015 12:04:13 UTC
@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.
Saturday, 18 July 2015 22:40:48 UTC
I, too, am a diabetic C# developer. We need a t-shirt: "Diabetics write the sweetest code."
Jeff Humphreys
Wednesday, 05 August 2015 13:44:30 UTC
I have gathered a collection of great Roslyn packages.
Tuesday, 11 August 2015 10:40:21 UTC
@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/
Monday, 17 August 2015 01:45:55 UTC
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.