Visual Studio 2017 officially launched March 7, 2017. Microsoft, like they often do, presented a live 2-days event to which you were able to connect for free and watch many sessions mostly on the new stuff.
This month, I will present some basic stuff here on this newer version. Stuff like installation, solution loading settings, live unit testing, new refactoring features, IntelliSense improvements.
With 4 of my distinguished friends, I will be giving a presentation for the local launch party of Visual Studio 2017 in Montréal that will happen (or has happened) April 5th, 2017.
Don’t look for code to download, it is not the topic of this month article!
For the screenshots, I have used the BikeSharing demo app from GitHub. The same demo code Microsoft used during the launch.
Let’s first talk about installation.
Instead of downloading a big huge many-gigs install packages containing all the features possible, Microsoft decided to review the installation process completely. You now need to download a 1 meg only installer. You can download this installer from www.visualstudio.com. Once downloaded, you can run it.
Figure 1: The Visual Studio 2017 installer
As you can see on figure 1, I already have the Enterprise edition installed but you can still install the Community or Professional edition. You can compare the features (and also the limitations of the free Community edition) offered by the various editions at https://www.visualstudio.com/vs/compare/.
You also use this installer to modify, repair or uninstall an existing installation of Visual Studio.
If you are doing a fresh install or modifying an existing install, you will be presented a list of 16 workloads as shortcuts of installation. A workload is nothing more than a convenient way to install what you need. So, you need to go through these workloads and select those that you will use.
Figure 2: The 16 workloads
Once you have selected your workloads, you might want to click on the “Individual components” to review if there are any interesting options that were left unselected.
The installer will then run for a while downloading and installing the stuff you have selected.
While it might make sense for you at home to use the online-download-on-demand installer, there are other situations where it might not be the ideal solution. What if you have to install a classroom, or all the developers of your company, or if you live in a part of the world where an Internet connection is not as fast and reliable as on the Microsoft campus? For legal reasons (related to the packaging of the Android installer), Microsoft has not built an ISO file like they used to do in the past. If you want to create your own offline installer, there is still a way to build one. Scott Hanselman blogged about it in February. The official documentation is also available.
Opening the IDE for the first time
After the installation is completed, you can start VS2017.
There are 2 things I really encourage you to do right now before trying to open a solution.
The first thing is to connect to your developer account. If you have used that in the past with Visual Studio 2015, it will ease reconnecting to your solutions in source control.
The second thing you should do is to check for any notifications. If there are any notifications, the flag should be shown with a yellow background and catch your eye. If you have used the online installer, you surely have the latest and greatest bits but if you have an offline installer, chances are that updates will be available. I had an issue using the original release of March 7 (the solution was loading but the Solution Explorer was not showing any file). That issue and others were fixed on March 14.
Figure 3: Logging and Checking the notifications
Fast solution loading feature
One new feature of Visual Studio 2017 that will be appreciated by teams working on large solutions, is the Lightweight solution load. The benefit of this new feature, is that you will able to start working much faster than you currently do. But there are also some drawbacks! The loaded solution only contains the currently edited project. The loading of other projects is postponed until it is really required. You have to try by yourself if you like this feature or not. There are some other features of the Visual Studio IDE that might not work correctly when this is enabled (like the Edit and Continue). If you are using third party extensions, you will need to check if they are benefiting from this new feature. For sure, you will need to update them to the latest version.
You can also set that options for all the solutions that will be loaded but I recommend to keep it unselected. When you will open your solution, if Visual Studio consider it is a solution that would benefit from that new feature, it will prompt you asking if you want to enable this feature for that solution only.
Figure 4: Lightweight solution load for all solutions
You can enable and disable that feature for a single solution if you right-click your solution and select Enable (or Disable) Lightweight Solution Load.
In the Solution Explorer, you will see the word “lightweight” to the right of the solution name if your solution is loaded in this mode (because you need to be aware that some features might not be fully available yet).
The start page
The Start page has also been improved. If you look at the right of the figure 5, you will find your source code control under the Open section (if you have logged in as said before). Without having to dig for the URL of your source control service, you will be connected in no time.
Figure 5: The new start page
The Live Unit Testing feature
Sad news for some of you. This is a feature that is only available in the Enterprise edition. Also, it is only available for C# and VB# projects targeting the .Net Framework.
This feature is really nice if you do (and I really you do) unit testing. Without having to lose the focus from the code you are writing, your unit tests will be re-run on the fly and your code editor will tell you automatically the state of your unit testing.
As shown in figure 6, there are 3 states to the unit testing: Succeed, failed, not covered.
Figure 6: The 3 possible states of unit testing
If you click on the green checkmark or the red X, the list of tests related to that line of code is displayed. You can even click one of the test in this popup and the code of that test will open in the editor. The navigation is really easy.
Figure 7: Looking at the list of tests covering that line of code
To enable the live unit testing, click on Test/Live Unit Testing/Start. Using the same path of menus, you can also Pause, Stop, or Restart the testing feature. You might also want to look at the Output dialog, there are some outputs specific on this feature listed there.
When I started testing this new feature using the BikeSharing demo solution, it wasn’t working. After a while, I figured it out. This feature is relying on some Nuget package that were apparently out of date on my machine. I just updated the packages and restarted the unit testing feature and I was finally able to see my testing icons.
This feature is reusing exactly the same tests you already wrote in your Test Explorer. In fact, they are integrated and synchronized.
There is also a section specialized in the Options dialog of Visual Studio named Lice Unit Testing. Depending on the speed of your computer and the size of your solution, it might be a good option to turn it off.
If you want to learn more about this great new feature, visit this blog.
New Exception helper
Here is a new nifty little improvement on the exception helper when you debug your applications.
I am sure you have already got an NullReferencException (see figure 8). If you have a long chain of dotted expressions (object.sub-object.sub-sub-object/…), I am sure you will agree that this dialog was of no help.
Figure 8: Null Reference Exception from VS2015
The Microsoft team has finally made it easier for us by showing a more specific error and dialog. As shown in figure 9, you now see very quickly that Notes is null. No more worries to try to find out which level is the issue, it is right there in your face.
Figure 9: Null Reference Exception from VS2017
Find all references improvements
Another dialog that got improved is the Find all References that you can get by right clicking on a member and selecting “Find All References” from the contextual menu.
As shown in figure 10, in VS2015, that dialog used to be a flat list.
Figure 10: Find all reference from VS2015
Now in VS2017, that list is now colorized, grouped, and sorted. Be sure to test out the group by combo at the top of this dialog. You don’t see it from that figure, but the dialog is now also searchable (top right of the dialog).
Figure 11: Find all reference from VS2017
Improvements to the IntelliSense
Another improvement this time in the IntelliSense dialog.
We all know that the list of members shown in that dialog can be rather long. If you know you want to look for properties, just click on the little icon from the tray of icons bar and the dialog will only show what you really want at this time.
Figure 12: IntelliSense filter tray of icons bar
Go to All
A very useful mechanism to navigate through your code by providing the member type. This feature is easily accessed by pressing CTRL-T.
As shown on figure 13, the dialog offers icons for types at the top. So if for example, you want to search for Types defined somewhere in your code, you can click on the Types icon or just type t space in the search textbox.
Figure 13: The “Go to All” dialog in action
You really need to play with this dialog 5 minutes to get all the benefits from it.
Some new refactoring tools have been added to the IDE.
For example, if you have a file that contains multiple classes (that often happen when you are prototyping and not taking the time to create one file per class), you can now move that type (class) to a specific file in no time. Just click your class name, press CTRL-. and press Enter. A file will be created (with the name of the class) and your job is done!
Figure 14: a new refactoring trick
Code suggestions and the .editorconfig file
Enforcing a coding style can be a nightmare when working in teams.
To try to help ease that task, VS2017 now supports the .editorconfig file. That file has to be at the root of your solution. And because it is a file that can be checked in your source control, it will follow the solution and requires the same coding style to be followed by all the team members.
This file as many options but to illustrate how it can be used, I will just show one change and how it is used.
If you open the .editorconfig file in a C# project, and search for a key named “csharp_style_var_for_built_in_types”, by setting it to “true:error”, that would cause any statement like “var x = 1;” to trigger a compile error. You don’t absolutely need to trigger an error, it could also be a warning or just a suggestion.
Figure 15: an error would be triggered if you declare “var x = 1;”
One nice thing is that you have 1 config file by project. What is nice about it is that you can have different rules depending on the project you are working with. This can be useful when working with some older projects.
If you want to add that .editorconfig file to your existing project and easily edit it, I strongly suggest that you download the free tool by Mads Kristensen.
I still have some issues with that feature. My first issue is that a after you have change the config file, you need to close and reopen your code file to have the newly modified rules to be applied. The other issue, which is more critical to me is that the rules does not seem to be applied if the code file is not open. For example, if you a rule saying that an error should be raised on some coding style, and all the code files are closed and you rebuild your project/solution, the rules will not be triggered. Hopefully it will be fixed soon.
Another behavior you might find is that if you build your project and it contains code-styling errors, none of these errors are preventing the code from compiling! Don’t forget that after all, the code is valid. What I just don’t like is to have the coding-style errors shown in the same error list and real compile errors using the same Red-X icon?
My contacts from at Microsoft say that they are working these 2 issues but no ETA yet.
What was presented here only scratches the surface of all the new features.
I see many people saying that they already got those features by using external tools like ReSharper. I would say 2 things. One, not everybody has the opportunity to get ReSharper. Two, ReSharper still has a lot more to offer!
I have played with some pre-released versions of Visual Studio 2017 and was impressed by this version. The IDE has some neat new improvements that will help you being more productive.
And I haven’t introduced any new features of the language yet!