Visual Studio extensions you should(n’t) be using

In this article, we’ll talk about some of the extensions I use in Visual Studio. I do not consider this piece very technical, however I assume it might be interesting for some of you.

But…why the title?
Figure 1
Figure 1

I get it, you don’t understand the title. But let me explain. The very reason I used the negative, was to say one thing which applies to all extensions. They are going to be performance hogs. Regardless of whether we are talking about an extension as huge as ReSharper or one as small as WakaTime, the drawbacks will always exist.

Now let’s get to the extensions.

WakaTime

The companion extension to the famous web app. With a simple installation, prompting only for your account API key, this small service running it the background of Visual Studio allows me track how much time I code. It also gathers information about the time spent working on a specific project and how long I have been coding in a given language. Later I can compare my results with fellow developers from all over the world. According to their website, this extension supports 43 IDEs and editors, so you can continue tracking your progress even when working in other editors.

WakaTime Dashboard
Figure 2: WakaTime Dashboard

Price: free, more features for $9/month

Website: https://wakatime.com/

VS Gallery: https://marketplace.visualstudio.com/items?itemName=WakaTime.WakaTimehttps://wakatime.com/

Markdown Editor

This is one extension I like to use mainly for aesthetic reasons. It doesn’t really bring much to the table in terms of development, but it is nice to see my Markdown file in a more graphical manner. It is also a good way to make sure I am writing valid Markdown.

Markdown Editor
Figure 3: Markdown Editor

Price: free

Source: https://github.com/madskristensen/MarkdownEditor

VS Gallery: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.MarkdownEditor

ReSharper

I saved the most famous extension for last. Almost everybody in the C# industry has either used or heard about ReSharper – a tool developed by JetBrains, the guys and gals behind IntelliJ. It offers a completely revamped key scheme with a handful of shortcuts designed to speed up one’s workflow. Something I really love is refactoring automation. It constantly checks my project for redundant code or convention irregularities. Apart from that, it allows for easier navigation in my project.

Unreachable code
Figure 4: Unreachable code of an if-else statement

However, it is one of the biggest extensions out there and often crashes when working on large projects. This extension also supports C++ development in Visual Studio.

Price: $299 for the first year

Website: https://www.jetbrains.com/

Extension link: https://www.jetbrains.com/resharper/

Sources

Figure 1: https://media.makeameme.org/created/yesyes-i-dont.jpg

Figure 2: https://wakatime.gallerycdn.vsassets.io/extensions/wakatime/wakatime/8.0.6/1484615403449/149763/1/ScreenShot-2014-10-29.png

Figure 4: ReSharper website

Changing default project directory in Visual Studio 2017

Over the years, I got used to having all new projects created in the “Documents/Visual Studio 2017/Projects” folder. But for some reason, this setting was different when I recently opened Visual Studio. I spent a bit looking for a way to change it back and I believe I have found one!

Why would you want to do this?

After installing Visual Studio and hitting the New Project button, you are presented with a dialog window. Among many other settings, there is also a project directory at the bottom. This is generally “C:/Users/<your_account>/Documents/Visual Studio 2017/Projects”. While most people keep it this way, you might want all new projects be saved somewhere else, i.e. a Git directory.

HOW TO DO IT THEN?

It is very simple and very fast. All you need to do is fire up a new instance of Visual Studio 2017 (the same applies for earlier versions as well) and hit the Tools menu item at the top. Then select Options from the dropdown menu.

 

Open Visual Studio options
Open Visual Studio options

With the new window open, double-click Projects and Solutions in the left column and find the Locations row. On the right, you will find various text entries to tweak different settings in VS. The one you are interested in is dubbed Projects locations. Enter your new default project location here.

Enter the new location here
Enter the new location here

Click OK to save changes and enjoy your new settings!

Getting rid of weird HTML indentation in Visual Studio Code

When editing HTML files in Visual Studio Code I have always been driven away by the weird auto-indentation when typing out closing tags. Since I am used to writing opening and closing tags before adding any further child elements, I have refrained from using VS Code for this purpose.

In the latest versions there seems to be certain improvement, though it still isn’t perfect. Therefore I decided to dig into the topic a little more and believe I found a solution to satisfy one’s needs. We shall achieve this by adding a simple line of JSON into user settings within Visual Studio.

How…?

We’ll start off by launching a new instance of Visual Studio and opening an HTML file. When adding some content as described above, we end up with something like this.

How I don't like it
How I don’t like it!

You can clearly see that the body tag is indented to the right when it shouldn’t be.   Though this might be a thing of personal preference I wanted to help those, who are feeling the same as me.

The workaround here is rather simple. Just bring up Command Palette using the Control + P (on Windows) or Command + P (on macOS) key combo and search for “user settings”. Another approach is to hit Control + , (on Windows) or Command + , (on macOS). This will open two JSON files. The one on the right will be empty. Here we will set the editor.formatOnSave setting to true. So make your file look like this.

Format on save
Format on save

Now you can go back to your HTML file and hit save. VS Code will automatically format the file as to your desire.

Edited file
Edited file

Custom TextBox in WinForms

Just recently I had to deal with WinForms for the first time in a long while and I stumbled upon an interesting thought. How would I go about making a custom WinForms TextBox with some kind of ‘uncommon behaviour’? I dug deeper into this subject, did some research on it and I think I have come up with something that is worth sharing.

Little intro

As far as simple WinForms projects are concerned, customising behaviour of their controls can be done easily. However, if your project requires some TextBoxes to work traditionally and others to have been inbuilt with some validation logic, I suggest you follow the steps described in this piece.

I am going to demonstrate this on a project, where every a’ entered into a text box will become a ‘b’.

Let’s roll

To kick things off, create a WinForms project and name it whatever you want (I named mine CustomWinFormsTextBox).

Create new project
Create new project

Then right-click your project in the Solution Explorer and add a new class. I have chosen CustomTextBox as it’s name.

Set the class name
Set the class name

After the class is successfully created, make it a child of TextBox. Then in order to add the described behaviour, override the OnKeyPress method of the TextBox class. This method is called everytime we press a key on the keyboard while the TextBox is focused.

Edit OnKeyPress method
Edit OnKeyPress method

We are essentially checking if an ‘a’ has been pressed, in which case we would replace it with a ‘b’, that would then get displayed in the text box.

Now all that’s left to do is to add our CustomTextBox to the Toolbox window so that we can drag-and-drop it onto our form. The Toolbox won’t offer you custom control just yet. First you have to build your solution. Then if you search for CustomTextBox you should see it appear in the search results.

Search Results
Search Results

Now just simply drag and drop it onto the form, save your project and hit Start. If you try to enter ‘maniac’, the text box will show ‘mbnibc’.

Place CustomTextBox and Start the app
Place CustomTextBox and Start the app

Although I know this won’t come to good use to everyone, I still think it is worth knowing about it.

Adding Visual Studio Code to PATH

In connection with the last article regarding the basic concepts of working with ASP.NET Core MVC, I came up with a little tweak to speed up your development by at least a small margin. To make things clear enough I won’t go into much technical detail.

Consider the situation in which we were last time. We successfully created a new project and went ahead to open it in Visual Studio Code. What we did and always can do is to launch a new instance of Code and open the project folder by navigating to it in the Finder dialog window. While this approach works, I will show you a quicker way to do it.

Setup

Essentially, all that is needed to be done is to invoke a command that will do all the work for us.

  1. Launch Visual Studio
  2. Press Command + ShiftP, which will bring up the Command Palette.
  3. Enter “shell”.

    Command Palette within Visual Studio Code
    Command Palette within Visual Studio Code
  4. You should be presented with two results, one of them being “Shell Command: Install “code” command in PATH”. Click on this option and wait until the operation has completed. This usually takes no more that a second.

All is now setup. Let’s head to the usage!

Usage

So far, all seems a little easy, doesn’t it? Well…this part will be of no exception. Simply navigate to your project folder in a Terminal window and enter code . . This will instantly open a new Visual Studio Code instance with the project loaded. No further hassle.

This tweak helped me and I hope it will make your workflow a bit snappier, as well.