Office 365 Development with Visual Studio 2017 – Part 2

When Visual Studio 2017 was launched earlier this year, I wrote an article to provide a glimpse of how to get started with Office 365 development with VS 2017 and different project templates available in VS 2017. You can read it here.

Let’s continue our journey of Office 365 development with VS 2017 in this article.

Objectives

In this article, we will walk through creating and running Office 365 projects in VS 2017. Along with that, I will explain Office 365 Add-in concepts side by side.

We will learn the following in this article.

  • Creation of Excel add-in projects
  • Brief intro of Office 365 Add-in
  • When you should choose which type of project

Prerequisite

This article assumes that you already have installed Visual Studio 2017 with Office 365 development option on your PC. If not, then please read part-1 and follow the installation steps. You will not see the project templates mentioned in this article if you don’t have the correct version of Visual Studio with Office 365 development option.

To make sure which version of Visual Studio you are using, go to “Help” menu and select “About Microsoft Visual Studio” sub-menu in Visual Studio.

Make sure you are using Visual Studio 2017.

Office Development

I’m using Community edition of VS 2017 which is “Free, fully-featured IDE for students, open-source and individual developers”.

Office Development
Image credit: Microsoft

You can download VS 2017 Community edition here.

The Office 365 development options are same in all editions of VS 2017, namely Community, Professional, and Enterprise. So, it will not matter whichever edition of VS 2017 you have for following the steps of this article.

Getting Started

Let’s start with creating a new Office 365 project for the add-in.

Either click on the menu “File” -> “New” -> “Project” or on the “Start Page” under “New Project” section, click on “Create new project…”:

Office Development

In the “New Project” popup, expand “Office/SharePoint” category under Visual C# and click on “Add-ins”.

Office Development

You will see project templates for Word, Excel, PowerPoint, Outlook, and SharePoint add-in.

Let’s briefly understand about Office 365 add-ins.

What is Office 365 add-in?

With Office 365 add-in or Office add-in, you can build program/solution that extends Office applications and interacts with the content in Office documents. You can add new functionality to Microsoft Office clients or create new rich, interactive objects that can be embedded in Microsoft Office documents. Office add-in runs in Microsoft Office across multiple platforms, including Office for Windows, Office Online, Office for the Mac, and Office for the iPad.

For more information on Office 365 add-ins, read on Microsoft website here. I will cover more on Office 365 add-ins in a separate article later.

In the New Project popup, select “Excel Web Add-in”, then click OK.

You will see a “Create Office Add-in” dialog with following two options:

  • Add new functionalities to Excel.
  • Insert content into Excel spreadsheets.

    Office Development

Let’s quickly see what this means. We will understand by inserting some add-in in Excel.

Open Excel and create a new workbook. Go to “Insert” -> “My Add-ins” -> “See All…”:

Office Development

“Office Add-ins” dialog will open. Click on “STORE”, enter “Wikipedia” in search, once Wikipedia add-in appears, click on “Add” button next to it.

Office Development

The dialog box will close and you will see now that the “Wikipedia” add-in is added under “Add-ins” ribbon.

Office Development

Click on it and on the right side, you will see a new section.

Office Development

Anything you can do on Wikipedia website, now you can do from inside Excel only using this add-in.

This is an example of “Extend functionality” type of add-in. These types of add-ins let you do some work right from Office applications without opening any other application. If you want to create this type of add-in, you should select “Add new functionalities to Excel” option in “Create Office add-in” dialog.

Now, let’s see some other add-in examples. Once again in Excel, go to “Insert” -> “My Add-ins” -> “See All…”. In the “Office Add-ins” popup, click on “STORE” tab and search on “bubbles”,

Office Development

Click on the first row “Add” button. You will see in the top right under “Insert” ribbon, a new “Excel Bubbles” add-in is available now.

Office Development

Click on it and a section with bubbles is added into current worksheet.

Office Development

Click on the “Sample Table” bubble in this section. It will add some sample data in worksheet and populate bubbles as per data,

Office Development

This is an example of “Content” type of add-in which adds some content inside an Office application. If you want to create this type of add-in then you should select “Insert content into Excel spreadsheets” option in “Create Office add-in” dialog.

Let’s go back to Visual Studio now. We were on this popup,

Office Development

Let the selection be “Add new functionalities to Excel”. Click “Finish”.

VS will create a new Excel add-in solution with 2 projects,

Office Development

Before understanding “what” these projects are and “why” they are created, let’s first understand the composition of an Office 365 add-in.

An Office 365 add-in consists of two components,

Office Development
Image credit: Microsoft

  • XML manifest file
    specifies settings and capabilities of the add-in
  • Web application
    interacts with Office clients and documents

Now coming back to Visual Studio, in VS 2017 Solution Explorer, you will see these two projects:

  • ExcelWebAddIn1
    This is the manifest project containing the XML add-in configuration/settings
  • ExcelWebAddIn1Web
    This is the project which has all code defining the add-in & its interaction with Office document. It has JavaScript and HTML files which define the UI of the add-in.

    To provide same look and feel in the add-in as Office 365 clients, it uses Office UI Fabric JavaScript. I will cover more on Office UI Fabric JS in separate article later.

Let’s now run the project to see it working. Press F5, VS will build the solution and launch Excel to make your add-in available inside it.

In Excel, “Show Taskpane” button will be focused with a tool tip message,

Office Development

Click on the “Show Taskpane” button. The task pane area will be loaded on the right side of Excel worksheet.

Office Development

Please note that when you created a new Excel add-in project, VS 2017 has included some sample code in it. That’s why you see the text and button here. Also, if you note the worksheet has been loaded with some sample data,

Office Development

This sample add-in is for finding and highlighting highest value cell among the selected ones. To see it in action, select the sample data and click on “Highlight” button,

Office Development

The JS code will get executed and highest value cell among the selected cells will be highlighted.

Stop the running project from Visual Studio and let’s now see the code which made it work.

In the Solution Explorer, double click the “Home.html” file.

This is the file which contains all UI elements. The texts and button you saw in Excel add-in are defined here,

Office Development

In the Solution Explorer, double click on home.js file.

This is the file which contains all code to interact with Excel.

Office Development

It sets the button text to “Highlight” and also sets the JS function which should be executed when someone clicks on it, among other things.

The load sample data JS function which populates the worksheet with some random numbers,

Office Development

The code for finding the highest value cell and highlighting it,

Office Development

See how simple it is to get started with Office 365 add-in development? You must give it a try yourself using VS 2017.

The purpose of this article was to make developers aware of Office 365 add-in development using VS 2017 which I have done above. You have to come up with the idea of your add-in to create a real-life Office 365 add-in which adds some value to the Office clients.

That’s it for this article. I will cover more add-in options in next article.

Note: This article was originally published by me on C# corner website here.

Featured image courtesy: C# Corner

How to use Microsoft Graph Provider in Visual Studio Connected Services

In this article, I am introducing the newly added Microsoft Graph Provider in Visual Studio 15.3.1. This article demonstrates how a developer can use this feature to work with Microsoft Graph API.

If you don’t know anything about Microsoft Graph API, then I suggest you read something about it here.

To make this article meaningful, I am explaining it using a new Excel add-in project. There is no coding involved though.

Prerequisites:

There are some prerequisites if you want to follow the exercise I have shown in this article. If you just want to read and don’t want to follow any steps by yourself, then please jump to Let’s Start section in this article.

  • Visual Studio 15.3.1 with Office Development Tools

On August 18, 2017, Microsoft has released Visual Studio 2017 version 15.3.1. For more on this release see release notes here.

This article assumes that you have already installed Visual Studio 15.3.1, if not then you can download it here.

For more specific content on how to install Visual Studio, please read my article here.

You will also need to have Office Development tools installed while you install Visual Studio. Please read my article on that here.

  • Office 365 Developer account

You may have access to Office 365 thru your corporate account provided by your employer. But it is strongly advised that you don’t use that account. Instead of that, get an Office 365 developer account here for free and enjoy 365 days of Office 365!

For more info on that, please read my article on Office 365 developer program here.

Before moving further, let’s make sure that you are using the correct version of Visual Studio for following instructions in this article, otherwise it will not work. Multiple versions of Visual Studio can be installed side by side, including preview version, so it’s necessary to make sure of correct version you are working with.

In Visual Studio, Open the menu Help -> About Visual Studio:

About Visual Studio

Please make sure 15.3.1 is the version of your visual studio:

VS version

If that’s the version of your Visual Studio, then let’s start.

 

Let’s Start

Open Visual Studio 15.3.1 and click on “Create New Project…”

In the “New Project” window, Select “Visual C#“ -> “Office/SharePoint” -> “Add-ins” -> “Excel Web Add-in”:

new project

Click on “Ok” to create a new project.

In the next window that appears, select the option “Insert content into Excel spreadsheets”, then click “Next”

office addin 1.png

Select “Basic Add-in”, then click “Finish”

office addin 2

Visual Studio will create a new Excel add-in project for you.

Once Visual Studio is ready, open Solution Explorer, find “Connected Services” under your project and double click on it:

connected services 1

You will see the following screen:

connected services 2.png

Click on “Access Office 365 Services with Microsoft Graph” which is the core of this article.

You will be shown a window to configure access to your Office 365 services:

connected services 3

If you have your Office 365 developer account, then enter the domain name you selected in the “Domain” textbox. Don’t forget to add “.onmicrosoft.com” too.

connected services 4

I have entered my developer account domain, but masked it for security.

If that was the correct domain you entered, the you will be shown a sign-in window where you will enter the details you used while registering for Office 365 developer account.

connected services 5

If your login information is correct, you will be shown “Configure Application” section:

connected services 6

Let it be “Create a new Azure AD application”, and click “Next”.

Now the wizard will ask you for permission to different Office 365 sections. It’s up to you what permissions you want to assign. You can change it later.

connected services 7

Following are the permissions I selected under “User” tab:

connected services 8

Similarly, I also selected some permissions in other tabs.

Once you are done selecting permissions, then click “Finish”:

connected services 9

It will take some time for Visual Studio to configure the access. Meanwhile you will see a window like below:

connected services 10

Once Visual Studio is done with configuring access to Office 365, that window will close automatically. If there was any error, it will be reported to you. Otherwise you will see success message in output window:

output window

Also, if you note – under “Connected Services” in Visual Studio, Office 365 Services will have a green tick mark:

green mark

There is also something more which happened.

Go to Solution Explorer. Do you see under “Connected Services” a new folder of “Office365” has been added?

solution explorer

Those two files under Office365 folder are not too important programmatically. One is a link to Microsoft Graph documentation, another is a JSON file with link to getting started documents. But we will leave those untouched as of now.

Open the Web.config file and see what’s changed here. You will see under the appSettings tag, Visual Studio has added some configuration details:

config details

You will see client id, client secret, tenant id and domain are automatically inserted in this file based on the information you provided while configuring access to Office 365.

Visual Studio also created an application under Microsoft Azure Application Registration for you.

To check that, login to portal.azure.com with the same account as you used for configuring access to Office 365 above.

Once logged-in to Azure, under search type “app reg”:

app reg 1

Click on “App registrations” link.

Under “app Registrations” you will see an app with the same name as your project in Visual Studio:

app reg 12

The GUID under application id is what you will see in your web.config file. You will not see the client secret anywhere though.

Also, if you note under package manager, Visual Studio has already added references to MS Graph SDK:

nuget

See how easy it has been made by Visual Studio now to kick start your Office 365 development using Microsoft Graph?

This article’s purpose was only to make developers aware of the addition of Microsoft Graph under connected services in Visual Studio. I will cover the actual code to be written in a project to call Microsoft Graph API in another article some time later.

Meanwhile if you want to see by yourself how you can call Microsoft Graph using Visual Studio, please go to this link.

For my more articles on Microsoft Graph, please visit here. Please also visit my home page nilesh.live for list of all my blogs.

Header image courtesy: Microsoft

Marking Methods “Obsolete” In C# Class Library

Note: For my all articles on C#.Net / Visual Studio, please visit here.

The following are the objectives of this article:

  • What’s an obsolete method?
  • Why & when should a method be marked as obsolete?
  • Available options in C#

What’s an obsolete method?

A method in a class library which is old or out-of-use and some other method instead of this is suggested to be used.

Generally, when you are introducing some new functionality in your class library but still want to keep an old method intact for some time until the next big release then it’s better to mark that old method as “Obsolete” and offer new functionality in a new method.

Why & when should a method be marked as obsolete?

You are introducing some changes in your class library, and replacing a method with a new one with some added features, at that time it is a good idea to not suddenly remove that method from your class library because it may break some code. But if you mark that method as obsolete then it is an indication that this method is already out-of-use and something else should be used in its place.

Available options in C#

Let’s now see what options are available in C# to mark a method as obsolete.

Open Visual Studio 2015 or 2017 and create a C# class library project named “TestClassLibrary”:

C#

Add a new static class in that project names “TestClass”. Add the following method in that class,

public static string ToUpper(string input) {  
    return input.ToUpper();  
}

Now right click on solution and add a new console application project named “TestConsoleApplication”.

C#

Add reference of class library project in console application project,

C#

Go to the Program.cs class and add following “using” statement at top,

using TestClassLibrary;

Go to the “Main” method and add following code

Console.WriteLine(TestClass.ToUpper("test input"));  

Console.ReadKey();

Build the solution by pressing F6 and it should build fine without any error or warning.

Now, let’s go to the TestClass and mark the ToUpper method as obsolete. For that just add “[Obsolete()]” attribute above the ToUpper method.

The whole TestClass.cs will look like this,

C#

What have we done here?

We have marked the method with “Obsolete” attribute indicating its users that this method is now deprecated and will be removed in future release. So, it’s advisable not to use it.

If you go to the console application, then you will see a green line below the code where this method is called, if you move your mouse over that green line you will see the warning message,

C#

If you build the project and then see error list window, you will see a warning,

C#

Note here the warning code CS0612. It’s a compiler warning code. If you click on the link CS0612, then you will see Microsoft documentation for this code will open in your browser,

C#

But this does not look like a good direction to the programmers on what to use if not this method.

Let’s add one more method to class library.

Go to TestClass.cs in class library project and add following method which has better error handling and its culture-neutral.

public static string MakeUpperCase(string input) {  
    if (String.IsNullOrEmpty(input)) throw new ArgumentNullException(nameof(input));  

    return input.ToUpperInvariant();
}

Now we want to indicate to the programmers that instead of “ToUpper” method, they should use “MakeUpperCase” method. Add a message inside “Obsolete” attribute on top of “ToUpper” method:

[Obsolete("This method should not be used, Use MakeUpperCase instead.")]

The whole method will look like,

C#

What have we done here?

We have marked the method with “Obsolete” attribute and added a message to be shown to the user which can work as an indicator to use some other replacement method.

If you now build the project and go to the Main method, you will see a warning with the above message,

C#

Now this looks like a good direction to a programmer who is going to use your class library.

Later, if you think that you have given enough warning and time to programmers using your class library that they should not use this method, and you want to raise an error if they do, then you can convert this warning into error by passing “true” Boolean value after the message:

[Obsolete("This method should not be used, Use MakeUpperCase instead.", true)]

The whole method will look like this,

C#

What have we done here?

We have marked the method with “Obsolete” attribute and added a flag indicating compiler should raise an error if this method is used somewhere.

If you build your project now, it will throw an error,

C#

Use this error flag in your class library when you want to introduce breaking changes in code.

In summary, we have seen the following three overloads of “Obsolete” attribute,

C#

I have attached a sample project with this article, downloaded it and built it one by one by un-commenting only one “Obsolete” attribute at a time,

C#

Note: This article was originally published by me on C# Corner website here.

C# Digit Separator

Note: For all my articles on C#.Net / Visual Studio, please visit here.

 

Sometimes, when you want to represent a big integer or long literal in C# code, it becomes less readable and there are chances to misspell a digit too.

Consider the following example of a C# constant,

const int assumedPopulation = 1122339654;
You will find the one line code is neat and clean, but the numeric value/literal is not so readable.

It would be better if there was some digit separator like we have in Excel for numbers. Then, the number would be easy to read, like below.

1,122,339,654

With C# 7, Microsoft has introduced a digit separator. While it’s not the regular digit separator “comma” which we use everywhere, it’s underscore.

In C# 7, the same line of code can be written as,

const int assumedPopulation = 1_122_339_654;
Doesn’t it make the number quite easily readable?
And this digit separator does not affect its display on UI.

Write the following code in a C# 7 console app (With VS 2017), and check the output on the console. The digit separator will not be printed on console.

static void Main(string[] args)  
{  
   const int assumedPopulation = 1_122_339_654;  

   Console.WriteLine(assumedPopulation);  

   Console.ReadKey();  
}

The C# 7 digit separator can be used with long, ulong, decimal, int, uint, short, ushort, double, byte, float data types.

Note: This article was originally published by me on C# Corner website here.

Data Type Suffixes In C#

Note: For all my blogs on Visual Studio / C# / .NET, please see here.

The objectives of this article are:

  • What is a data type suffix?
  • Why is a data type suffix required?
  • How and when to use a data type suffix?

What is a data type suffix?

In C#, while specifying any value of a variable or literal, a literal is a source code representation of a value and you can append some specific character after the value/literal, which is called a data type suffix. e.g.

  1. var myVal2 = 4294967296L;
  2. var myMoney = 300.5m;
  3. var myRadius = 3.145f;

As shown in the above examples, the L, m and f suffixed after the literals are data type suffixes.

For the scope of this article, I will cover the two types of literals given below to which data type suffixes can be applied:

  • integer-literal
  • real-literal

Why is a data type suffix required?

The data type suffix helps the compiler to unambiguously identify the data type of any value/literal. It also helps C# programmer to explicitly state the data type of the value/literal.

In the cases when a variable is declared, using one of the “var”, “dynamic” or “object” keywords, use the data type suffix to explicitly state the data type of the value.

In case of integer literals, if you don’t specify any suffix, then the integer values are evaluated to a data type, as per the sequence given below.

  • int
  • uint
  • long
  • ulong

In case of real- value literals (those with decimal points or fractions e.g. 3.14), if you don’t specify any suffix, then a real- value literal is evaluated to a data type, as per the sequence given below.

  • double
  • float/decimal (based on suffix)

In short, without any data type suffix, an integer literal will be evaluated to int and real literal will be evaluated to double.

There are data type suffixes given below.

  • L or l for long
    • (l in small letters should be avoided as it confuses you with digit 1)
  • D or d for double
  • F or f for float
  • M or m for decimal
    • (D is already taken for double, so M is best representation for decimal)
  • U or u for unsigned integer
  • UL or ul for unsigned long

There are no data type suffixes for int, byte, sbyte, short, ushort. Previous versions of C# used to have “Y” and “S” suffixes for byte and short respectively, but they were dropped from C# specification after being found, which are not often used by the programmers.

As a C# programmer, you should be aware of these data type suffixes and make use of them in your programming, so that you won’t have any surprises when your code is executed.

How and when to use a data type suffix?

As stated earlier, you as a programmer do not want C# compiler to decide the data type, as per default specification, then use the data type suffixes.

In the examples given below, I will show the usage in C#. Create a Visual Studio project for C# console Application and in the Program class, create the two methods given below:

public static void TestMethod(int i)
{  
            Console.WriteLine("You called integer version of TestMethod");  
}  

public static void TestMethod(long l)  
{  
            Console.WriteLine("You called long version of TestMethod");  
}

You must have seen the code given above to create two overloaded methods with the same name “TestMethod” but different int and long arguments. There is not much logic in the method except the message to be written on the console to identify which one was called. You can imagine that there is a specific code here to do different operations for int and long data types.

Now, in Main method, write the two lines of code:

TestMethod(5);  

TestMethod(5L);  

Console.ReadKey();

You must have noticed two different integer literals passed as parameters to TestMethod. How does the compiler now decide which method to call?

Press F5 to execute the program. You will see the result given below.

c#

The literal “5” without any suffix got evaluated to int, hence the TestMethod with int parameter was called. The literal “5L” got evaluated to long, hence the TestMethod with long parameter was called.

Now, comment out the above three lines in Main method and write the code given below, followed by clicking F5.

var myVal1 = 429496;  

TestMethod(myVal1);   

var myVal2 = 429496L;  

TestMethod(myVal2);

You will see the same output as in previous case due to the same reason.

Now, add the new overload of TestMethod in Program class given below.

public static void TestMethod(uint i)
{  
 Console.WriteLine("You called UNSIGNED integer version of TestMethod");  
}

In Main method, write the code given below and click F5.

var myVal3 = 429496u;  

TestMethod(myVal3);  

Console.ReadKey();

You will now see the third overloaded method and the one, which you just added will be called.

c#

We will see now the programming in case of real value literals.

Comment out the above 3 lines, which you just added for unsigned int. In the Program class, create the three new overloaded methods given below.

public static void TestMethod(double i)
{ 
 Console.WriteLine("You called double version of TestMethod"); 
}

public static void TestMethod(float i) 
{ 
 Console.WriteLine("You called float version of TestMethod"); 
}

public static void TestMethod(decimal i) 
{ 
 Console.WriteLine("You called decimal version of TestMethod"); 
}

In the Main method, write code given below. Subsequently click F5 for the execution.

var myVal4 = 9.99;  

TestMethod(myVal4);  

var myVal5 = 9999999999999999999999999999m;  

TestMethod(myVal5);  

var myVal6 = 3.145f;  

TestMethod(myVal6);  

Console.ReadKey();

You will see the output given below on the console.

c#

Note here that any real literal (those values with fraction point/decimal) will be evaluated to double by default. Hence, the first call executed the TestMethod with double parameter.

A similar example with dynamic keyword is covered in my attached code, so I am not writing it here.

Let’s see what the compiler says when we use lower case.

Write the line given below in Main method, followed by clicking F6 to build the project.

var longTest = 12345l; 

Go to “Error List” Window and click Warning header to see the warning,

c#
There is no error but it warns us to use capital L to denote long literal because lower case l can be easily confused with the digit 1.

Note: This article was first published by me on C# Corner website here.

Installation Of Visual Studio 2017, A Firsthand Explanation

This article tries to give a firsthand and quick introduction to installing Visual Studio 2017, highlighting some of its new features.

Today, Microsoft has launched Visual Studio 2017, the latest IDE for developing “mostly anything” in the Microsoft platform as well as developing apps and Websites, which target Android, iOS and Linux.

If you have already registered for the Microsoft Visual Studio 2017 launch event, then your mailbox may have an email from Microsoft regarding resources related to VS2017, else you can click here to get started with downloading VS2017.

Moreover, if you download VS2017 by March 14, you will get free 60-day access to Xamarin University, which will help you in a great way to enhance your Xamarin skills.

You can choose to install either community, professional or enterprise editions. This article explains the features of the enterprise edition. If you want to know what’s in the different editions, then you can read more here.

If you want to check the installation requirements, you can read more here.

Once you have clicked on your desired edition, the Browser should prompt you to save the installer file.

Visual Studio 2017

Click Save File button to save this installer file to your download folder.

Also, note that once download starts, your Browser will show a “thank you” page with this message related to “Xamarin University”.

Visual Studio 2017

In this article, we are not going to touch anything related to “Xamarin University” but will concentrate only on VS2017.

Meanwhile your installer file may have been downloaded, click on the file to run it. You will be prompted with the message given below.

Visual Studio 2017

Click Yes to continue. You will be prompted with yet another popup, as shown below.

Visual Studio 2017

Click again to Continue.

This release of Visual Studio will show you a new light weight installation approach, which is quite different from the past versions of IDE.

Clicking on “Continue” in the previous popup will show you the installation launch screen given below.

Visual Studio 2017

This is a new “modular” installation experience, where you can tailor VS to install only the components, as per your needs.

You can maximize the installation screen to see more details.

There are 3 tabs here: “Workloads”, “Individual Components” and “Language packs”.

Workloads

It contains a choice for which type of development work you are going to do with VS2017 e.g. Universal Windows Platform development, Desktop development (with Win Forms, WPF), Web development, Mobile development, Office365 development etc.

If you wish to install a development Workload, you can choose it by clicking on the top right checkbox.

Visual Studio 2017

Individual components

This section contains choices to install some tools, which were previously being installed separately as some “packs”. You can see different versions of .NET Framework here like Azure Cloud Explorer and some other MS Azure related tools like Azure Storage Emulator, Azure Data Lake Tools etc. Some SDKs for Android, Windows 10, Typescript  etc. are also there, where you need to choose the ones in which you are interested in by clicking the checkbox in front of the item.

Visual Studio 2017

Language packs

This section offers some language choices for VS2017. English will be selected by default. Most of you may not need any other language.

Visual Studio 2017
Some more points to be noted here  are given below.

There is no “Select All” feature in this new installation, which I really miss. You must go and manually select the components.

Check the right side of the installation Window and it shows Summary as you go on selecting the features.

Visual Studio 2017

You can expand individual items to see what’s inside that and there are some more choices.

Visual Studio 2017

If you need support of some of these sub-features, you can select them by clicking on the check boxes.

You can change VS2017 location at the bottom of the Window.

Visual Studio 2017

At the bottom-right of the installation Window, you can see the approximate installation size (which changes as per feature selection).

Visual Studio 2017

Once you have explored all 3 tabs and sub-features from the “Summary” section and when you are ready to go, click Install button.

You will be shown the screen, which shows installation progress as VS2017 is getting installed.

Visual Studio 2017
Let the installer do its work. While VS2017 is being installed, go and grab a cup of coffee.

Once the installation finishes, you will be prompted to restart.

Visual Studio 2017
It’s a good idea to restart your PC now, as the installer may have changed many things on your PC. Save your important documents, which may be open, click Restart.

Once restarted, find VS2017 in start menu, or type “Visual Studio 2017” in run prompt. There will not be any shortcut on the desktop.

Once loaded, you will be shown a welcome screen.

Visual Studio 2017

Now, again a prompt is there to choose developer settings and theme.

Visual Studio 2017

Make a selection as per your liking and click Start Visual Studio.

Congratulations.

You have installed Visual Studio 2017.

Visual Studio 2017

If you want to read the release notes for VS2017, click here.

Now, go and install the trial version of VS2017 by yourself, write some code, get your hands dirty!

Check for my next article on some new features in VS2017 here.

Note: This article was published by me on C# Corner website here.

Header Image credit: C# Corner

Visual Studio 2017 New Features

In this article, you will be acquainted with Visual Studio 2017 and its new features

Welcome to another article on VS2017. I’m sure that you have already read my article on installation of VS2017. If not, then read it here.

In this article, I will demonstrate some new features of Visual Studio 2017 IDE, which will help a lot in your day to day development.

Creating new project with VS2017

Open VS2017 and you will be shown a welcome page.

There are two ways to create a new project in VS2017.

You can write the type of project, which you want to create in the textbox below “New Project” header.

You will be shown the type of projects as and when you type in the textbox.

e.g. writing “console”:

When you write WPF:

There is also another way to create a new project. Click More project templates link just below the textbox. You will be shown a familiar dialog box to create new projects.

What’s new in Visual Studio IDE

Let’s start by creating a console Application. I will introduce some of the new features in VS2017.

Improved code navigation

After creating a console Application, go to Solution Explorer and right click on the project to add new class.

Let’s say that we are adding new Customer class given below.


Now, save the Customer.cs file and go to Program.cs.

Write Customer in the Main function, press either Ctrl + T (Control key followed by T key) or Ctrl + , (Control button followed by, key).

On the top right, you will be shown a pop-down dialog, which will help you quickly locate the referenced element. Notice that it will quickly launch the “Customer.cs” file too.

In this way, you can have a look at a referenced class and its properties quickly without the need to open the relevant file in IDE. You can simply press ESC key, the dialog, file and both will close.

“Fuzzy” matching

VS2017 introduces a new feature called “fuzzy matching”, which means when you type a name and even if you misspell it, VS2017 will show you the results, which are based on fuzzy match.

To experience it, let’s go to Program.cs -> Main method again.

Type “Cstomer” and see.

VS2017 will automatically suggest you “Customer” class and highlights it for you


Changes in References window

Write the line given below in Main method.

 

  1. Customer cust = new Customer();

 

Now, place the mouse cursor on “Custmer” word, press “Shift” + “F12” keys.

You will be shown a new “references” Window, which has been modified compared to “Find Symbol Results” Window in VS2015.

Notice in the “references” Window, there are many new things here like Filtering (on left side), Group by, Search, “Keep Results” button, Sorting and Colorization.

Let’s see each of them one by one.

Filtering references

In VS2015, when you find all the references on a class or property, you will be shown all the referenced results with no option to filter them. Now, in VS2017, you have filtering option in references Window.

See on the left side that there is a drop-down and by default Entire Solution is selected.

You can filter the references; based on which area you want to see and VS2017 will only show you the relevant references.

Grouping

With the “Group By” feature, you can change how the references are being displayed. It provides you the options given below, which helps you in quickly navigating to the reference; you are looking for,

Let’s say you select “Definition, Project then Path” option and you will see the references group, as shown below.



Search

On the top right section of “references” Window, you can search inside the “references” results.

Keep results

This is a new interesting feature. Remember in VS2015 when you are already looking at one references result and you want to find another class or property reference too. If you search in another class reference, your previous result will be overwritten. You can see only one reference result at a time.

If you press “Keep Results” button on the references Window and you search for another term, then your original result will be preserved and you will be shown references in a new Window.

Let’s say that you create a new “Order” class and reference it from Main method.

Press “Keep Results” button on the references Window of customer results, go to Order class and press Shift + F12. You will be shown references in another Window.

At the bottom of the Window, you will be able to find a tab for “Customer” references too.

Sorting

You can now click on the results column headers like Code, File, Line, Col and Project to have your references result sorted by these columns, which were missing in VS2015.

Colorization

Notice the references are displayed in different colors to help you in clear understanding of the references.

Structure Guide Lines

A dotted vertical line now runs between the curly braces to identify scope. If you mouse over the dotted line, then you will be shown the current scope.


Code Refactoring enhancements

VS2017 has improved refactoring a lot to make the code more readable.

Let’s consider some new improvements.

Object initialization

If you have written the code step by step to assign the values to an object’s property, VS2017 refactoring will now suggest you to use an object initialization.

Write the code given below in Main method.

Now, place your mouse cursor on Customer and press Cltr + . (Control key followed by .)

VS2017 will give you a message “Object initialization can be simplified”.

Click on the suggestion and your code will be modified, as shown below.


Also, there are some more such enhanced features, which you can try yourself:

Inline Out variable.

Simplify null checks.

Add missing case(s) to a Switch statement.

And much more

There are many more new features of VS2017 but for the scope of this article, I will restrict to above five only.

Go and install Visual Studio 2017 on your PC to find out more by yourself.

Happy coding!!!

Note: This article was published by me on C# Corner website here.

Header Image credit: C# Corner