Tuesday, March 13, 2018

The Magic of Visual Studio and GitHub Integration

The more I use Visual Studio 2017 and the integration with GitHub, the more I am amazed at just how well this all works. I'll use a real-world walk-through with some Espressif ESP32 Arduino code that I am using on my M5Stack to show how really useful this is.

First, note that I have a couple of add-ins installed (Tools - Extensions and Updates). In particular the Arduino IDE for Visual Studio and the GitHub Extension for Visual Studio.


I was reading this thingpulse blog entry on reducing ESP32 power when I noticed the line:
WiFi.forceSleepBegin();

Hmm... interesting. But when I tried to use that, it seems to not be implemented for me:


So here we can right click on WiFi and Go To Definition:


And sure enough.. the WiFi.h file opens... but as a "soft" open tab on the right, instead of the regular solution file on the left; hmm. there's no forceSleepBegin() in the header. Let's see if we can find out more.


It gets more interesting, as now we can right click on the WiFi.h tab name and select Open Containing Folder:



So here I can see which of the several (in my case Arduino or ESP32) WiFi libraries are actually being used in this project. In the path we see the ESP32 library is being referenced:



Now.. this directory was installed via a git clone command some months ago.

Even more cool, is we can right-click on Windows Explorer and Open in Visual Studio. (yes, going back!) Be sure to click on white page in the Explorer file list, and not on a specific file. Otherwise only that single file will be opened.



Note how the ~\src directory is opened in the solution. Looking closely, there are little lock symbols next to each file! I didn't do anything to set that up. It just works!


Yes, those little locks say "this is a file under source control and has not been checked out nor edited".

Next, to really see the magic, click on the Team Explorer tab (or View - Team Explorer).



Look! A Welcome to GitHub for Visual Studio message. It just knows that this subdirectory has a parent directory somewhere above that has the git clone repository information. How cool is that!?!

Click on the Sync Button/Tab and we can see the incoming commits, LIVE from GitHub!

Here we can press the Fetch link to just bring in the historical information, but not change our local files.


Want something else? Click on the master Branch text/link, to view the other branches:


Double-click to select a different branch. All the usual git commands apply, so git stash is probably your friend here. (unfortunately manually from command line, as far as I know)

Sadly, the "Search Work Items" does not seem to work for me; I cannot type anything there. That will soon be a Very Cool feature.

We can however, right-click on commit items and compare & see what changes by pulling each commit:


All from the comfort of the Visual Studio UI. How really awesome is that!?! :)

Close the yellow welcome message banner and we can see exactly where this repository lives on GitHub. Press the little home icon any time in Team Explorer to return to this view:


Click on the repository link and the GitHub web page for the repository (in this case Espressif Aduino repository on GitHub) opens in your default browser.

As a suggestion, there are probably some files that should be added to your .gitignore file. Simply going though this exercise creates some files that you probably don't want to push back to the repository and may interfere with pulls. Click the Changes tab/button on the Team Explorer home to see what's been added:


These will of course interfere with selecting other branches, etc.

Overall this is really quite cool. The developers creating Visual Studio simply rock. :)

There's a ton of other cool stuff going on. Be sure to check out The Visual Studio Blog and the Visual Studio conversation in the Gitter community.


Other links:

No comments:

Post a Comment

comments are welcome, but I prefer not to allow links to promotions or other unrelated services.

Find gojimmypi at gojimmypi.github.io

I'm currently working on my new blog home at  gojimmypi.github.io After implementing a variety of features such as dark mode , syntax hi...