Visual Studio 2017 is now available, download it here. I've been converting my projects over to VS2017 and wanted to share my favorite features of the new IDE.
My favorites are Go To All, move type to matching file, string splitting, and coding conventions via EditorConfig. Other notable mentions are the overhauled Find All References and Go To Implementation search features, the Lightweight Solution Load option, and the Add Package Reference feature.
Go To All
Go To All is a new feature that lets you search your entire code base for files, types, and methods. If you know what you want, you can filter to just the right kind of results. Furthermore, in C#, F#, and VB it will perform fuzzy matching to find results even when you make a spelling mistake.
To start your search, press
CTRL+,. Then enter the file name, type name, or method name you want to find. To filter the results, start your search with an
f to filter to just files,
t for types, and
m for members.
In the following example I'm searching the SimpleInjector code base for
t lifestyle, which finds all the types containing "lifestyle".
Move type to matching file
It's often convenient to start by creating multiple types in a single file, this lets you rapidly develop them together in one place. But once you move beyond prototyping and start to flesh them out, it becomes cleaner to have each type in its own file.
Until now, it's been quite tedious to move types into their own files. But Visual Studio 2017 fixes that with a new refactoring that lets you move a type to a matching file with a simple
CTRL+. on the type declaration.
There are also new rename refactorings for quickly syncing the file name and type name. Again, these are accessed by
CTRL+. on the type declaration.
Sometimes you have a long string and you want to split it over several lines. Previously you had to do this manually, by adding additional quotes and a
+ to concatenate the strings. Now you just move the cursor to the point you want to split at and press
If I have this string:
"This is a really long string and I want to split it up into multiple strings!"
ENTER with the cursor on the s in split, I get this:
"This is a really long string and I want to " + "split it up into multiple strings!"
Simple and convenient.
Coding conventions via EditorConfig
You can now codify your coding conventions at any level of granularity and enforce them as suggestions, warnings, or even errors using EditorConfig. This makes it easy to keep the style of your code consistent.
Configurable conventions include the usage of
this, usage of language (
long) vs framework (
Int64) type names, usage of object and collection initializers, naming of tuple properties,
var vs explicit type names, usage of expression-bodied members, and more. You can find a list of all the options in the .NET Code Style Settings reference.
The conventions are easy to codify using the following format:
options_name = false|true : none|suggestion|warning|error
options_name selects which convention to configure, setting
false sets how to apply the convention, and
error specified how to enforce it. As an example, here is a rule for enforcing that
var should be used when the type is apparent, i.e. when the type is mentioned on the right-hand side of the declaration. If
var is not used in these situations, this rule produces a compile time warning.
csharp_style_var_when_type_is_apparent = true : warning
EditorConfig files also let you apply different convensions to different parts of your project. EditorConfig files are named
.editorconfig and apply hierarchically to the files at the level of the
.editorconfig file and to all files below it. You can then override the rules at any point in the hierarchy by adding another
.editorconfig file. For example, the
.editorconfig file in
Folder applies to
Class4, and the
.editorconfig file in
Subfolder can override some or even all the rules for
Unfortunately, at this stage you cannot set naming conventions through EditorConfig. These must be set through the global Visual Studio options, which means they cannot vary across solutions or within projects. You can follow the progress on this feature in this GitHub pull request.
If you decide to use EditorConfig to codify your conventions, grab the EditorConfig Language Service extension by Mads Kristensen. It adds syntax highlighting, intellisense, validation, and more for
Overhauled Find All References and Go To Implementation
Find All References and
Go To Implementation search features have been completely overhauled and now feature colorization, filtering, grouping, sorting, and searching within the results. Making these useful features even better and a lot more powerful.
Here's an example of what
Go To Implementation offered in Visual Studio 2015.
And here's the improved
Go To Implementation in Visual Studio 2017. Much prettier, more informative, and more powerful.
Lightweight Solution Load
For those large solutions containing tens, hundreds, or even more projects you can now enable Lightweight Solution Load to make loading these solutions much faster.
You can enable Lightweight Solution Load globally in
Tools Menu / Options / Projects and Solutions / General or for an individual solution by righting clicking on the solution in solution explorer and selecting
Enable Lightweight Solution Load.
I tested Lightweight Solution Load on the SimpleInjector code base, which consists of 30 projects, and found the load time on opening Visual Studio went from just over 16 seconds to under 8 seconds. I suspect the improvement would be even more pronounced on larger solutions containing more projects.
Add Package Reference
The final new feature that caught my eye was the
Add Package Reference feature. This helps you by adding the missing assembly reference when you try to use an unrecognized type and can even suggest NuGet packages if that option is enabled.
To enable this feature, goto
Tools Menu / Options / Text Editor / C# / Advanced and tick
Suggest usings for types in reference assemblies and
Suggest usings for types in NuGet packages.
There are lots of great new features in Visual Studio 2017 and I've only covered features that are in every version of VS2017 (Community, Professional, and Enterprise) and of those, only my favorites. If you have the Enterprise version, there are many other awesome new features like Live Unit Testing. To discover all the new features, read the full release notes for Visual Studio 2017.