Working with Git Branches in Visual Studio 2019

Continuing our previous posts, let us now see how we can work with branches within Visual Studio 2019.

Branches give the option to isolate the work from the original code base, this way we could have a developer(s) working on bug fixes, new features etc. which then can be merged back to the master branch later.

Open the Branches page in Team Explorer and click on the New Branch option.

Here we have created a new branch name MyFirstBranch from the master branch, and have also selected the option Checkout branch to work with that branch.

Create Branch creates the new branch as shown below.

To navigate to the branches page of Team Explorer, we can also use the Status bar of Visual Studio

Now let us make some changes in the program.cs file in the new branch created.

Do Commit and Push
All

From the team explorer, Branches page, we can see that the new branch has been added in the remote repository after commit.

To merge changes back from this new branch to the master branch, click on the master branch and select Merge option in the Branches page

  • Merge from Branch: MyFirstBranch
  • Into current branch: master.

As we have selected the option Commit changes after merging click on Merge pushes and sync the changes in the master branch in the remote repository as shown below.

We also have the options of deleting the branches as shown below, if they are not required anymore.

In this post, we saw how to work with Branches and how to merge it back to the base code.

Hope it helps..

Perform basic Git operations with Visual Studio 2019

In the previous post,

https://nishantrana.me/2019/10/21/getting-started-with-git-repository-in-visual-studio-2019/

we learned how to setup and  get started with Git Repository in Visual Studio 2019.

In this post, we will learn how to perform some of the basic operations like commit, push, fetch, pull, etc. and how to merge the conflicts.

Let us open the solution created in the last post and make some changes

Here we have updated Program.cs and added a new class file Helper.cs


To commit these changes, we can either go to Team Explorer – Home – Changes page or click on the edit icon in the status bar of the Visual Studio.

After we have added our commit comments, we are presented with 3 different options

Commit All Commit will make a record of the changes in the local repository.
Commit All and Push Commit the changes locally and push the changes to the remote repository.
Commit All and Sync Commit the changes locally, fetch the changes from the remote repository and finally push the changes to the remote repository

We can also use the Stage option to break the commit into smaller stages

We will be presented with similar options for Commit Staged as in the case of Commit.

Perform Commit Staged and Push for both the changes.

We can see both the updates in our remote git repository

Other developers or team members who need to work in the project can Clone the project in Visual Studio 2019.

Provide the Repository location URL along with the local path.

Now suppose the developer 1 makes the below changes to the program.cs and does commit all and push.

The other developer 2, can click on Fetch in the Synchronization page to see any incoming commits.

Clicking on the commit shows the details of the changes as shown below.

Developer 2 can click on Pull to merge commits to the local master branch.

fetch Download the changes from remote repository
merge Applies the changes fetched to a branch in the local repository
pull fetch + merge

Now suppose developer 1 has changed the message and commit + push the changes to the remote repository.

And also, in parallel developer 2 has also updated the same message and has clicked on Commit and Push.

As both have made changes and referencing to the same line of code, the developer 2 gets the failure message when he tries to push his changes to the remote repository.

Message in the output window à

Developer 2 here can click on Fetch to see the changes

Developer 2 clicks on Pull to merge the changes and can see the conflict.

Clicking on Conflicts gives Developer 2 the option to Merge, Take Remote or Keep Local the changes.

Selecting the Merge option allows developer 2 the option to specify the merge.

Clicking on Commit Merge to merge the changes, followed by appropriate Commit operation to push the changes to the repository.


This resolves the conflict.

Thus, in this post, we learned how to perform basic operations like Push, Pull, Fetch, etc. and how to merge and resolve the conflicts using Visual Studio 2019.

Hope it helps..

Getting started with Git Repository in Visual Studio 2019

Let us go through the steps to set up a Git Repository in Visual Studio 2019.

Open Visual Studio 2019

Go to Tools à Option and Set Git as source control plugin (if not set)

To create a new Repository, select Home àProjects and New Repository.

Provide the path and click on Create.

Click on the repository created to open it in the Team Explorer.

Click on Changes, which shows the files added as part of the creation of the Git Repository.

Click on Commit Staged to add the files to the local repository.

To sync it to the remote repository, we can click on Sync.

Now to add the solution to the Git Repository, back in the Home page of team explorer, click on New for the Solutions.

Follow through the Wizard. Here we have added a new solution of type Console Application to it.

Again, go back to Changes and click on Commit All.

To see the history, go to Home – Branches page, right-click on the master branch and select View history.

It shows the details of the 2 commits done locally in the local git repository.

Now to push the changes to Remote Repository

Click on Sync.

Click Publish Git Repo

Provide the URL of the Remote Repository.

Here we have created a new repository.

https://github.com/

Copy its URL.

Specify the URL and Publish the changes to the remote repository.

After successful publishing, we can see the files added in our remote GitHub repository

In Team Explorer – Home – Branches we can see the remote branch created.

To work with an existing remote repository within Visual Studio 2019, we can go to start page, select Clone or check out code option.

Either provide the URL or sign in to the GitHub account and choose the repository to clone.

Within Team Explorer also we can Clone the repository by using the Clone option

In this post, we saw how we can create a local repository, add the solution to it, publish it to the remote repository.

Hope it helps..

New features of Visual Studio 2019 – Code Clean up, Faster Debugging, Refactoring, Live Share

Earlier we covered below features

Let us have a look at the other new features, that are now part of Visual Studio 2019 (couple of features were available with VS 2017 as marketplace extension earlier)

Health Indicators
à With Health Indicators, which can be found at the bottom of files in Visual Studio 2019, we can quickly get a glance at how many errors and warnings are there in the file.

Code Clean up
à Along with health indicators, we can also see the icon of Code Cleanup, which allows us to apply fixes to the code.

Configure Code Cleanup settings let us define the fixes to be part of the profiles as shown below.

Code cleanup can also be run for the entire solution from Analyze à Code Cleanup

  • Debugger stepping is not 50 % faster in Visual Studio 2019 compared to Visual Studio 2017.
  • The Watch, Autos and Locals Windows are 70 % faster.
  • Font and Colors of Visual Studio 2019 can be customized through Tools à Options à Environment à Fonts and Colors


  • Indent for the parameters of the method can be specified easily


Result à


  • Signature for the parameters can be easily changed using the Change Signature dialog box

Result à

Now let us have a quick look at the most interesting feature i.e. Live Share

With Live Share, enables real-time Code Collaboration, using
we can easily share the source code/ terminal from our machine for code review or for technical help with the team members. Earlier the options were to check in the code in the repository and then asking others to get the latest or share the screen / have a meeting set up.

To get started,

Click on Live Share icon,

Select Copy Link

Here we are sharing it with one of the team members having Visual Studio Code. Live Share works with Visual Studio 2017 (with extension)/ 2019 and Visual Studio Code (with Extension) and any OS.

Click on Join Collaboration session and paste the link.

Both the users have the ability to move across the code, make changes together within their environment.

Debugging session can also be initiated/shared from both environments, without having the other user to install any specific packages/tools/plugins, etc.

Also with Live Share Extension Pack, we can add Chat and Audio Capabilities to Visual Studio Code

https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare-pack

That is not all, we have Live Share Whiteboard and Pomodoro extensions as well.

Check the below article that explains all the functionality of Live Share in detail

https://dev.to/lostintangent/visual-studio-live-share-in-pursuit-of-enjoyable-developer-collaboration-2nko

Hope it helps..

New features of Visual Studio 2019 – IntelliCode

IntelliCode to be very precise provides Artificial Intelligence to the code.

Basically, it will provide suggestions (AI) by displaying at the top the frequently used properties, functions, etc. as shown below.

For DateTime, IntelliCode is suggesting Now, UtcNow, MinValue and Today, as these are the ones that are used frequently.

Similar for our IOrganizationService class of Dynamics 365 CE, it suggests RetrieveMultiple, Execute, Retrieve
Update, Associate as the most frequently used methods.

To enable it.

Navigate to Tools à Options à IntelliCode

Enable the required features à

The IntelliCode gets its intelligence to give recommendations based on the huge number of open-source projects on GitHub with more than 100 stars on which it has performed machine learning and have the models defined.

The interesting part is that we can have intelliCode work for our code as well.

From within the Project, Navigate to View à Other Windows à IntelliCode Model Management.

Select Create a new model à

It will start the training and will store the generated model locally along cloud to be referred in case if working offline.

The model can be shared, deleted and retrained.

For e.g. we have the following class

And within our code, we are making use of FullName property frequently.

Now after training (retraining), it would suggest FullName as the property for our SampleClass that is being used frequently.

Get all the details here

https://visualstudio.microsoft.com/services/intellicode/

Hope it helps..

New features of Visual Studio 2019 – New Search Experience and UI changes

Visual Studio 2019 comes with a completely revamped, context-sensitive Search experience.

To change the Theme, search for keyword “Theme” and select the appropriate result.

It would open the respective screen, which allows us to quickly make the changes.

Similarly, to change the Font.


Also, observe the option to “Search online for ‘Font'”, which opens the search result in the browser. It appends the “Visual Studio 2019” keyword to the search term.

The search result is also context-sensitive,

For e.g. search results when a search is performed when the context is the file within a project.

The search results when Solution is selected inside Solution Explorer.

Recent results screen

With regards to UI changes, we now have the new Start Page

Clone or check out code lets us open the Git Repository quickly

Create a new project allows, search for the project template and filter it as well

The toolbar changes, top one is 2019 one and the bottom one is Visual Studio 2017. Project Name has moved to the right in the toolbar and it is now 2 rows. Quick Launch is now replaced with the Search box.

Automatic downloading updates.

The above useful changes are surely going to be loved by the technical community who always loved Visual Studio.

Hope it helps..

New features of Visual Studio 2019 – Export / Import Visual Studio Configuration Settings

Within Visual Studio Installer, we now have the option to export and import the configuration settings. These configuration settings can then be shared with the team to import, which makes sure that all of them have the same set of workloads installed in their Visual Studio environment.

Select the version of Visual Studio and click on Export Configuration.

Click on Review Details to check the workloads part of the configuration

Here we can see .NET desktop and ASP.NET workload to be part of it.

The content of .vsconfig file

To import it, click on Import Configuration.

Select vsconfig file and click on Review Details

Click on Modify to install the workload/components.

The installation begins and installs the required components.

Hope it helps..

My Favorite – Visual Studio Tips and Tricks

Sharing some of my favorites

  • Select entire line of code

Put the cursor anywhere in that line of code and without selecting anything just press ctrl + c or ctrl + x

Here I have put my cursor just before the var declaration.

Pressing ctrl + x will cut the entire line


  • Use ALT key to make selection from middle of the line spanning multiple lines and replace the content.

Press and hold Alt while making the selection to select the content from the middle, instead of beginning of the next line.

Also, here we can start typing to replace the content.

  • Change selected text’s case

  • Ctrl +] to move to the matching brace and Ctrl + Shift +] to select everything between matching braces.


  • Move between methods inside using Visual Studio

Using Edit à Next Method and Previous Method we can easily navigate between the methods


  • Use cw code snippet for Console.WriteLine


  • Show Output Window when build starts

Navigate to Tools à Options to enable this setting

  • Use Shift + Enter to place “;” at the end of line
  • Use Peek Definition to get details of the referenced property or method


Use Preview Tooltip for vertical scroll bar

Go to Options à All Languages à Scroll Bars and check Show Preview Tooltip

This will show the preview of the source code at that point.

Hope it helps..

Nice article on understanding Code Map in Visual Studio

Hi,

Recently had a requirement to document and show stack trace for a particular method to understand the flow

No better way to do it than through code map using Visual Studio

http://blogs.msdn.com/b/zainnab/archive/2013/02/07/visual-studio-2012-update-1-understanding-code-map.aspx

Bye..

Generating Class Diagram using Visual Studio 2013

Hi,

Currently working on some documentation, so had to generated some class diagrams. Visual Studio 2013 provides us modelling project which can be used for generating the class diagram.

Check this article

http://blogs.msdn.com/b/cdndevs/archive/2014/08/11/working-with-class-diagrams-let-visual-studio-2013-do-the-work.aspx

Hope it helps..