Visual Studio 2017 – What’s New

Initially named “Boston”, Visual Studio has gone through a number of transformations in the last two decades. Right from its Visual Basic and Interdev days, Visual Studio has evolved with every release to address new markets and provide improved experiences across multiple platforms and devices.

Visual Studio 2017 (VS 2017) is the 11 th version of Visual Studio with a focus on improving experiences around mobile apps, cloud services and devops.

New IDE features like interactive code suggestions (intellisense), easy code navigation, debugging, fast builds and quick deployment are some of the productivity and performance enhancements in VS 2017.

This article explains some of the most important features of VS 2017 which are useful for boosting developer productivity.

Visual Studio 2017 can be downloaded from this link .

Are you keeping up with new developer technologies? Advance your IT career with our Free Developer magazines covering C#, Patterns, .NET Core, MVC, Azure, Angular, React, and more. Subscribe to the DotNetCurry (DNC) Magazine for FREE and download all previous, current and upcoming editions.

Visual Studio 2017 New Features

A new installation and setup experience

Assuming you have downloaded VS 2017, run the setup for a new installation experience, as shown in the following image:

The installation allows you to choose and install just the features which you need; which makes the installation faster.

The Workloads tab provides installation options which are grouped to represent common frameworks, languages and platforms. The main advantage of grouping is that a developer can easily choose a feature set to be installed based on their needs e.g. only Windows Features or Web and Cloud features etc.

These group are as follows:

  • Windows
  • Web and Cloud
  • Mobile & Gaming
  • Other Toolsets

If you don’t want to go the Workloads route, no worries! The Individual components tab allows you to pick the components you require, as shown in the following image:

Some options in Individual components are listed here:

  • .NET Framework
  • Cloud, database, and server
  • Code tools
  • Compilers, build tools, and runtimes
  • Debugging and testing
  • Development Activities
  • Emulators
  • Games and Graphics
  • SKDs, libraries and frameworks

The advantage of the new setup experience is that, now one can choose only those features which are needed for his/her development. Individual components can be used by advanced developers to further customize these features of Visual Studio.

The Language packs allows you to choose the language for Visual Studio.

The VS installer, by default, tries to match the language of the OS when it runs for the first time. The following command can be used to force an installer to run in the selected language:

vs_installer.exe -locale 

  

The following language token are supported by the installer:

en-Us, zh-cn, zh-tw, cs-cz, fr-fr, de-de, it-it, ja-jp, ko-kr, pl-pl, pt-br, ru-, u, tr-tr,

Once VS 2017 installs and is launched, the start page is displayed as shown in the following image:

The start page shows options like Recent and Open, which are similar to the previous version of Visual Studio e.g. VS 2015, but a new feature worth observing is to create a New project using the Search project templates search box or the Create new project link.

A new project can be created by entering the project category in the search box as shown in the following image:

Once the project category (e.g. Web Ap) is entered in the textbox, all matching project templates are searched and displayed. Once the project template is searched and the name of the template is clicked, the New Project window will be opened. The same New Project window will also open on clicking the Create new project link.

Note: If this is not a fresh installation and you have already created projects using VS 2017, then before you start searching for project templates, the recently used project templates are listed.

Once we create a solution, it will be added in the Recent solution list.

The solution may contain several projects in it, which increases the solution loading time. When the solution is clicked from the Recent list (or else File > Open > Project/Solution), by default, it will be opened with all projects in it. However it is not necessary that the developer will be working on all projects at the same time, so Visual Studio can now be configured to load the solution in a lesser time using Tools > Options > Projects and selecting Lightweight Solution Load option as shown in the following image:

The Enable option decrease time for loading the solution. This option also results in some limitations e.g. projects will still be loaded as needed when first accessed (directly or indirectly) and in this case, features like edit and continue won’t work.

IDE Enhancements for Developers

Step 1 : Create a Console Application of the name ‘CS_NavigationFeatures’. In the project, add a new class file called Employee.cs and add the following code in it:

namespace CS_NavigationFeatures
{
    public class Employee
    {
        public int EmpNo { get; set; }
        public string EmpName { get; set; }
        public int Salary { get; set; }
        public string DeptName { get; set; }
        public string Designation { get; set;}
    }
}

Open Program.cs and create an instance of the Employee class.

VS 2017 has enhanced navigation experiences for developers to move from one point to another. For e.g. a developer can easily navigate all Employee declarations that matches with the word entered in the search box, which can be opened using a short-cut key Ctrl+T.

Using the shortcut brings up a navigation pop-down dialog on the top-right corner of the Visual Studio as shown in the following image:

Enter Emp word in the search textbox of the dialog box, which will show all references matching the word Emp as shown in the following image:

Here a developer can select where to navigate to e.g. to an Employee class, Employee.cs file or other Emp references e.g. members. All this facilitates an easier code navigation, with less distractions.

One of the important features of this dialog is the icon-menu-bar on the top. This icon-menu-bar provides options for selection of code navigation e.g. File, Class, member, etc.

The following image explains it in details.

For e.g : to navigate to a file, File Navigation > Symbol is ‘f’

..which shows files starting with the matching search criteria:

Type Navigation (applied to class, interface) > Symbol is ‘t’

..shows classes matching with the search criteria:

Member Navigation > Symbol is ‘m’

..shows all members matching the search criteria:

Using Reference window

While writing code, developers creates several code files and refer to various types at various places for defining instances e.g. Employee references in various files.

In Visual Studio 2017, these references can be easily searched using an improved reference window.

In the project, add two new class files of name Manager.cs and Payroll.cs and add the following code in it:

Manager.cs

namespace CS_NavigationFeatures
{
    public class Manager
    {
        public Employee emp { get; set; }
        public int TravelAllowance { get; set; }
        public int HouseRentAllowance { get; set; }
    }
}

Payroll.cs

namespace CS_NavigationFeatures
{
    public class Payroll
    {
        Employee emp;
        Manager mgr;
        public Payroll()
        {
            emp = new Employee();
            mgr = new Manager(); 
        }
    
    }
}

Program.cs is as shown in the following code:

namespace CS_NavigationFeatures
{
    class Program
    {
        static void Main(string[] args)
        {
            Employee emp = new Employee();
            Console.ReadLine();
        }
    }
}

In the three code files we just saw, an Employee object is used for instance creation and property declaration.

Now it is easily possible to find out all the Employee references for the current project. Select Employee declaration in Program.cs as shown in the following image:

Now select Shift+F12, and the ‘Employee’ references window will be displayed as shown here:

This window will list all Employee references in all the file names.

Just by clicking on the reference, the file can be opened in the VS Editor. The type reference details (in this case Employee ) can be seen just by moving the mouse cursor on a specific line or reference it as shown in the following image:

For e.g. in the above image, a reference of an Employee in Payroll.cs is displayed in the tooltip.

In VS 2015, it was possible to find all references on a class or property and there was no option to filter it. But in VS 2017, these references can be filtered as shown in the following image:

The references can also be grouped as shown in the following image:

The references window also provides a facility to search from the references using the search textbox on the top-right corner of the window, as shown in the following image. The search can be based on the File name, Column number as well as the Line number.

This shows all Employee references from Program.cs file.

The Keep Results toggle button in the references window will make sure that all the references will be saved. The advantage of this feature is that, when new references are searched; instead of overwriting previous references, the new references will be shown in a new tab of the reference window as shown here:

The above image shows references for Manager and Employee.

Automatic Suggestion for NuGet Package for Unknown types

As a developer, when some code is added in the application, sometime it happens that the developer knows the class to be used in the code, but the name of the package from which this class is used, is not known.

In this case, a developer sometimes searches online for help but such help is not always helpful (pun intended). For e.g. a developer who wants to use the DbContext class or a JObject class but does not know which NuGet package needs to be installed for the project.

In VS 2017 (also in VS2015.3), there is an option available for Suggest usings for types in NuGet packages in the Tools > Options > Text Editor > C# > Advanced as shown in the following image:

The checkbox for Suggest usings for types in NuGet packages is not checked by default, please check it and restart VS 2017.

Open Program.cs and try to use DbContext class, select this class name and press Ctrl+. Doing so brings up the quick action menu with suggestion for installing EntityFramework package as shown in the following image:

Once the Install package ‘EntityFramework’ option is selected, the package will be installed and its status will be shown in the VS 2017.

I hope you too realize what a cool feature this is!

Structure Guide Lines for Current Scope

When the code file contains several classes and a class contains several lines of code with several programming constructs (if…else statements, for loops, etc.), while scrolling down in the VS editor, it is at times difficult to track the scope of the current statement.

In VS 2017, the code contains dotted lines between curly braces to identify the scope. When the mouse is moved over the dotted lines, the current scope is displayed as shown here:

Variable Name/Parameter Name Declaration Suggestion

This is another cool feature of VS 2017. This feature provides suggestion for defining variable name in a class/function as well as input parameters to the function. This helps to follow naming standard for variables/parameters in the application.

To experience this feature, add a CalculateSalary() method in the Payroll class in Payroll.cs file. Define the Employee object as an input parameter for this method. VS 2017 will provide name suggestion for the input parameter as shown in the following image:

In the Payroll class, try to declare a Manager object. VS 2017 will show the suggested name for the declaration of object, as well as for methods too.

This helps to keep coding standards in check.

Coding Style Configuration

There are some more suggestions settings provided by VS 2017 for validations and coding styles. These suggestions can be set using Tools > Options > Text Editor > C# > Code Style as shown in the following image:

For e.g. in the above image for ‘var’ preferences, the For built-in types is set to value for Preference as Prefer explicit type and Severity as Suggestion. In this case, if the code variable contains declaration as shown here..

..then the var declaration has dots below it, which means that there is a suggestion available for the declaration. Press Ctrl+. on var , and a quick action menu will display suggestions for the var declaration:

Here an explicit type can be selected instead of a var declaration.

Likewise, there are several suggestions provided in the options windows which can be helpful to provide a better coding experience. I would encourage you to explore them all.

Improvements in Code-Refactoring

Code refactoring is a major activity that developers must perform while writing code. This makes the code maintainable and readable. In VS 2017, there are some features which provide some great Code-refactoring experiences. Here are some of them:

Object Initialization

C# 3.0 already provided a new syntax for object initialization, but consider this code where object properties are initialized in a manner as shown here:

To change the above code using the Auto-Initialized syntax of C# 3.0, VS 2017 provides a new feature.

Observe the underlined dots below the new keyword for object creation. Now move your mouse cursor on the new keyword, to bring up a pop-up that shows the message Object initialization can be simplified :

Click on the down-arrow of the quick action menu, to bring up the new object initialization refactoring suggestions as shown in the following image:

Select Object initialization can be simplified and you will find that the code will be refactored as below:

How convenient! We could change the object declaration/initialization in a jiffy!

Managing null value check for the reference of input parameters of method

When a method accepts a reference type (e.g. Employee object) as an input parameter, then while accessing that method, it is important to check for a non-nullable value for the input parameter, before passing it to the method. Alternatively, the method must have code for checking for a null value.

In VS 2017, this feature is provided so that a method can be added with the required null check.

In the Payroll class in Payroll.cs file, add the CalculateSalary() method as shown in the following code:

public void CalculateSalary(Employee emp)
{

}

To check the null value for the emp object, right-click on emp and select Quick action and Refactorings option from the context menu as shown in the following image:

This will bring up the Add null check option as shown here:

Once this option is selected, the method will be added with a null check condition:

Likewise, if the method accepts a string parameter, the code can be refactored to generate conditions for string.IsNullOrEmpty and string.IsNullOrWhiteSpace check in the method.

This useful feature helps developers to reduce logical errors in the code.

Changing the method signature

When a method having various input parameters in a specific order needs to changed either by removing some parameters or changing order of parameters, then it will definitely result in to a compilation error.

If the method is called at various places in code, the Developer would need to manually keep track of changes in the method and update the code accordingly.

This is a time-consuming task!

In VS 2017, the signature of the method can be easily changed and these changes can be reflected at all places where this method is called. This saves the developer some precious time and makes the code error-free.

Consider the following PrintName() method in the program class of the Program.cs file.

class Program
    {
        static void Main(string[] args)
        {
            PrintName("Mahesh","Sabnis");

            Console.ReadLine();
        }
        static void PrintName(string fname, string lname)
        {
            Console.WriteLine($"First Name {fname} Last Name {lname}");
        }
    }

The PrintName() method accept two string parameters fname and lname .

This method is called in the Main() method with the values set for fname and lname as Mahesh and Sabnis respectively.

If we need to change an order of fname and lname in the PrintName() method, then in the Main() method, values for these parameters needs to be changed manually.

In VS 2017, this can be done easily by refactoring the method.

Right-click on the method name and select Quick action and Refactorings option from the context menu.

Doing so will show the Quick Action menu with a Change signature option as shown in the following image:

Clicking on the Change signature option will show a Change signature window.

Using this window, the order of parameters in a method can be changed or they can be removed altogether.

In the image you just saw, click on the button with the downward arrow and move the fname parameter below the lname parameter. Now click on the Ok button, and you will see that the method signature and its call will be updated.

Once the PrintName() method signature is updated, the PrintName() method call with its parameter values is also updated.

The advantage of this feature is that it reduces potential errors which a developer can make while updating the method definition in the application.

Debugging and Exception Handling Improvements

Once the code has been written, it is important for a developer to debug the code to ensure that the code is logically working and has been diagnosed for exceptions, if any.

In VS 2017, there are some improvements made for debugging and exceptions management.

Debugging Run to Click

In previous versions of Visual Studio, when breakpoints were applied on various lines, it was necessary for developers to press F5 to skip lines in between two breakpoints, to continue debugging from next breakpoint.

Or, for the developer to skip the current breakpoint and continue debugging ahead, it was necessary to put additional breakpoints. In this case, it was necessary for the developer to keep track of all breakpoints (imagine a for/foreach loop occuring in between the code).

To get rid of this, in VS 2017, a new feature known as Run to Click is added (similar to Run to cursor feature of the previous version), which allows the developer to skip the lines in between breakpoints and start executing code from the desired line.

Consider the following image. A breakpoint is applied on the PrintName() method, so the debugger will stop at this method.

If the developer does not want to stop an execution at the PrintName() method and wants to continue execution directly from the Reverse() method call, just move the mouse cursor adjacent to the Reverse() method, and a Run Execution to here symbol will be displayed as shown in the following image:

Click on this symbol, and all the lines of code in between PrintName() call to Reverse() method calls will run past it, and the Reverse() method call will be highlighted as shown in the following image:

This means that an execution is continued from the Reverse() method call, hence there is no need to apply a breakpoint at the Reverse() method call.

The New Exception Information Helper

Dealing with exception is a common developer problem irrespective of the technology.

Figuring out the reason for an exception is one of the most frustrating experiences. In previous Visual Studio versions, exception information messages used to be displayed as shown here:

In this case, it was challenging for the developer to find out the exact exception and it was necessary to see the View Details and Inner Exception to find out what is the reason behind the exception.

In VS 2017, a new non-modal exception handling helper is provided as shown here:

This helper shows an exception message and provides the reason behind the exception. In this case the Object reference is not set to an instance of an object exception is fired and the cause of the exception is also displayed as m as null.

This helps developers to understand what is the reason behind an exception and how to handle it. The main advantage here is that, earlier it was required for the developer to see the Inner Exception in the View details dialog; however in the VS 2017, the in-detail exception information is seamlessly provided to the developer.

Live Unit Testing

Apart from all the above features discussed, there is one more important enterprise feature provided in VS 2017, and that is Live Unit Testing.

This feature encourages Test Driven Development (TDD) and helps in developing betterquality code and code coverage. You can read more about Live Unit Testing at http://www.dotnetcurry.com/visualstudio/1363/live-unit-testing-visual-studio-2017 .

Conclusion

Visual Studio 2017 is packed with improvements and new features that increase productivity. This all-new IDE released by Microsoft helps developers to build stunning apps on Windows and other platforms.

I hope this article served its purpose and introduced you to these productivity features which will help you simplify your most common tasks, and ultimately boost your productivity.

This article was technically reviewed byDamir Arh andSuprotim Agarwal .

稿源:.NET Curry.com (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合技术 » Visual Studio 2017 – What’s New

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录