Visual Studio 2017 makes you more productive by getting you to your code fast and helping you write code quickly. With improvements to performance, navigation, and debugging as well as the additions of new refactorings, code style configuration/enforcement, and live unit testing, this release is chock full of advancements. This post shows you how to take full advantage of these features.
Getting Started
Visual Studio 2017 significantly cuts down the time it takes to install, open Visual Studio, and write code in your solution. The new Visual Studio installer gives you the freedom to pick and choose exactly what you want installed.
After you install Visual Studio, you’ll notice how much faster the VS startup time and solution load time are:
- The improvements made on Visual Studio startup time are illustrated in this blog post featuring a side-by-side video comparison.
- You can enable lightweight solution load to lazily load projects. This is especially helpful if you work on a solution with hundreds of projects but you personally only work in one or two of those. You can enable lightweight solution load by going to Tools > Options > Projects and Solutions > Lightweight solution load for all solutions. Note: lightweight solution load does not work with F# projects.
Navigating Your Codebase
Visual Studio 2017 refreshes the navigation experience to help you get from A to B with greater confidence and fewer distractions:
- Go To Implementation (Ctrl+F12) – navigate from any base type or member to its various implementations.
- Go To All (Ctrl+T or Ctrl+,) – navigate directly to any file/type/member/symbol declaration. You can use the icons along the top of the feature to filter your result list or use the query syntax (e.g., “f searchTerm” for files, “t searchTerm” for types, etc.).
- Find All References (Shift+F12) – now with syntax colorization, Find All Reference results can be custom grouped by a combination of project, definition, and path. You can also “lock” results so that you can continue to find other references without losing your original results.
- Indent Guides – dotted, gray vertical lines act as landmarks in code to provide context within your frame of view. You may recognize these from the popular Productivity Power Tools.
Writing Your Code
In this release, we have made a bunch of small tweaks and additions to help automate common tasks and speed up your workflow:
- IntelliSense– filter your completion list by category by clicking on the icons in the tray or by hovering over them to learn the keyboard shortcut. This is great when you are learning a complex API or working in WPF and specifically looking for only properties or events, etc.
- Refactorings – use ‘Ctrl+.’ to access all the refactorings and quick actions we’ve added in VS. Here is an overview:
- Move type to file with same name
- Sync file and type name
- Add missing switch/Select case
- Make method synchronous
- Convert method to property, and vice versa
- Convert to interpolated string
- And many more!
- Add using/Imports for types in reference assemblies/NuGet packages– if you type an unrecognized type, we will search for it in your reference assemblies and on NuGet.org and offer a quick fix to add the using/Imports. This feature is off by default; to enable it go to Tools > Options > Text Editor > [C#/Basic] > Advanced > Suggest usings for types in reference assemblies and Suggest usings for types in NuGet packages. Enabling the latter option will download 10 MB of a NuGet index on your machine and it will take several seconds to complete (this will not affect your workflow in VS, but it does means you cannot immediately use the feature once enabling it).
- Code Suggestions – code suggestions let you hint best practices to developers. They surface in the editor as gray dots and you can apply suggestions with the command “Ctrl+.”.
Driving Consistency and Readability
In Visual Studio 2017, you can configure and enforce your team’s coding conventions to drive consistency across your entire repository with EditorConfig. EditorConfig is an open file format and we worked with their community to support .NET code style within this format. Teams can configure convention preferences and choose how they are enforced inside the editor (as suggestions, warnings, or errors). The rules apply to whatever files are in the directory that contains the EditorConfig file. If you have different conventions for different projects, you can define each project’s rules in different EditorConfig files if the projects are in separate directories. Because, at the end of the day, EditorConfig is just a text file, it’s easy to check it into source control and have it live and travel with your source.
If you do not wish to use an EditorConfig file or you want to configure rules that your team hasn’t explicitly set, go to Tools>Options>Text Edtior> [C#/Basic]>Code Style to configure your machine local settings.
To get language service support when editing an EditorConfig file in VS, download Mads Kristensen’s extension. Learn more about coding convention support in VS2017 by reading our documentation or our post on the .NET blog.
Testing Your Code
Live Unit Testing reveals the impact of a code change on your unit tests almost instantly without you having to shuffle between the editor and the Test Explorer to manually run your tests. The icons on each line of code illustrate whether the line is hit by all passing tests (green check), at least one failing test (red ex), or if it is not covered by any tests (blue dash). To enable Live Unit Testing for your solution, go to Test > Live Unit Testing > Start.
For those of you with large solutions, we enable you to select which tests you want to be “live”. From the Solution Explorer, you can right-click on a project to Include/Exclude it from the Live Test Set or if you are within a test file, you can highlight a group of tests and right-click to Include/Exclude them. You can play with other settings for Live Unit Testing by going to Tools > Options > Live Unit Testing.
To learn more about Live Unit Testing and how it can save you time and effort, read this blog post.
Debugging
Visual Studio 2017 builds upon the debugging experience to help you identify the source of an issue faster:
- The new Exception Helper puts the most important information from an exception at the top-level, like inner exception details and the expression that returns null. From the Exception Helper you can also choose to disregard certain exception types while debugging—such as exceptions thrown by third-party libraries.
- Run To Click executes a developer’s program until it reaches the target line of code and breaks in debug mode. This feature saves you time by acting as a temporary breakpoint.
- XAML Edit and Continue lets you change your XAML while your app is running so that you can continuously tweak your UI. Note: this feature was originally added in Visual Studio 2015 Update 2.
- Reattach To Process enables you to quickly reattach to previous debug targets. After you have manually attached once, you don’t have to waste time in the Attach to Process dialog to debug that same application. You can find this feature under Debug > Reattach to process… or with the command “Shift+Alt+P”.
Moving Your Code Forward with C# 7.0 and VB 15
The release of Visual Studio 2017 coincides with the final versions of C# 7.0 and VB 15. The new language features in these releases help you work with data and write more condensed code.
When adopting these new features into your everyday development, note:
- To use tuples in C# and Visual Basic you must have the ValueTuple package installed. If you enable the Add using/Imports for NuGet package setting mentioned in the Writing Your Code section, you can add this package with one-click via “Ctrl+.”.
- We added a ton of quick actions to help you embrace new language features, such as:
- Use throw expression (C# 7.0) and null-coalescing operator (??) to simplify null-check.
- Use explicitly provided tuple name (C# 7.0).
- Use pattern-matching (C# 7.0) to simplify null-check.
- Convert string.Format or concatenated string to an interpolated string (C# 6.0).
- Use expression-bodied member for methods/constructors/indexers/properties/operators/accessors (C# 6.0/7.0).
Don’t forget to follow the language design for C# and Visual Basic on our new GitHub repos, CSharpLang and VBLang.
Learning Hotkeys
Become a power user of Visual Studio by familiarizing yourself with common shortcut keys outlined in this cheat sheet. If you are coming to Visual Studio from another IDE, try Justin Clareburt’s Hot Keys 2017 extension to remap the default Visual Studio shortcuts to the ones you are used to.
Downloading Visual Studio 2017
With all the improvements to performance, navigation, debugging, refactorings, code style configuration/enforcement, and live unit testing there is no time to waste! Download Visual Studio 2017 today and take advantage of all the productivity features we have added to save you time and effort.
If you think we are missing a refactoring or quick action, please let us know by filing an issue on our GitHub.
Kasey Uhlenhuth, Program Manager, .NET & Visual Studio @kuhlenhuth github.com/kuhlenh Kasey is a program manager on the .NET Managed Languages team at Microsoft and is currently working on modernizing the C# and VB developer experience. Previously, she worked on C# Interactive and Node.js Tools for Visual Studio. |