Skill Level Intermediate
- [Instructor] I've recorded a lot of tips in my other courses that I think you'll find useful. This tip is from my Visual Studio Essentials series. It's here in the Extend and Customize the Visual Studio Environment course. I thought I would revisit this tip on how to use the Comment Remover extension. Before showing the tip, I have some housekeeping notes. The source code for this video is in the Weekly Tips Git repository. You can see it down here in the bottom. It shows Tip038. You might notice that the solution name is different in the original video and that there is this additional solution folder, but that doesn't impact the example.
Enjoy this week's tip. In this movie, I'll look at the Comment Remover extension. It's a simple tool that removes all the comments in the Editor window. It can also remove Regions and knows how to selectively handle C# XML documentation comments. I've already installed the extension, so I'll click on the Close button in the Extensions and Updates dialogue. Then I'll open this Stylesheet1.css file. As you look through this document you can see that I have a number of comments. I have a Block comment here at the top.
I've got some inline comments here on line 12 and line 14, and I've got a header comment here at the beginning of my Customer Styles. I'm ready to submit this CSS file to my client for review and I want to remove all the comments before doing so. To use the Comment Remover, I'll go to the Edit menu and choose this menu item, Comments, and then this top item here, Remove All. As you can see, it successfully removed all the comments and didn't impact the rest of my CSS. It left that alone. Comment Remover works for any file type that supports comments, so it'll also work in this HTML document, and it works in C# files.
In this C# file I have two constructors that have some line level comments, line 18 and 19 inside this constructor, and I also have the same comments here in this other constructor on line 29 and 30. I also have an XML comment here which is used for documentation purposes. And of course, I also have several regions. I have a region here called Constructors, and I have a region here that contains my Properties. To remove all the comments, I can go to the Comments menu and choose the same menu item I've used on the other demos.
That's not what I want to do. I want to remove all the comments except the XML docs. If I choose this one, you see that it removed the comments within this method and this method but it left my XML comments alone. I can also choose to remove the XML doc comments and leave the rest of my comments, very nice. Finally, I can go up here and choose to Remove Regions. So that removed the Properties region that was around these two properties, and it also removed the Constructor region that was around my two Tour constructors.
And again it didn't touch the rest of my code. It left it alone. Now that we've seen the Comment Remover, let's look at it from an extension developer perspective. The main feature of the IDE that it exploits is the ability to modify the code in the code editor. It does this by examining the code, finding the comments, and removing the necessary lines. It also has to be smart to remove the begin region tag and end region tag and not destroy the code in between. Also it adds a custom menu to the menu system which gives the user a place to activate the extension features.
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.