← all posts

A 'Hello World' for VSTS Extensions

Gordon Beeming
Gordon Beeming
On this page6 sections ▾

So if you haven't heard yet VSO Extensions are now in a private preview where you can sign up to get into the preview on extensions integration site. These extensions in the shortest sentence a supported way of doing customizations to VSO that will replace any of the "hacky" extensions that you may be playing around with at the moment like Tiago Pascal's Task Board Enhancer or maybe you have even created your own following similar steps to what I show in my TFS 2013 Customization book.

This post aims to give you a super quick guide on how to get started, you will need to go through the integrations site to really get into detail. It has most of what you will find in most posts but gives you a little something extra that most posts wouldn't have like tips on free stuff 🙂

#File, New Project

The easiest way to get a basic something in VSO is to just create a new project.

#Create/Configure Project

We are going to create a new Type Script project

 

New Project dialog in Visual Studio with TypeScript selected
Visual Studio New Project dialog with HTML Application with TypeScript selected.

You should have something like below now

Newly created VSO Time Ticker project in Visual Studio Solution Explorer
Visual Studio Solution Explorer showing the newly created VSO Time Ticker project.

#Configure SSL in IIS Express

When you have the VSO Time Ticker project selected head over to the properties window

Visual Studio Properties window for the VSO Time Ticker project
Visual Studio Properties window highlighting SSL Enabled property for the VSO Time Ticker project.

Change SSL Enabled to True

Visual Studio Properties window with SSL Enabled set to True and SSL URL shown
Visual Studio Properties window with SSL Enabled set to True and the SSL URL displayed.

Take note of the SSL Url that is now available to you.

#Add a extensions.json

Let's add a extensions.json manifest file that will be used to inform VSO what our projects actually about

Visual Studio Add New Item dialog with JSON file selected
Visual Studio Add New Item dialog for adding the extensions.json manifest file.

and drop in the content below, replace the baseUri property to include the port you have been assigned for SSL for the project.

extensions.json
{  "namespace": "VSO-Time-Ticker",  "version": "0.0.1",  "name": "Time Ticker",  "description": "A simple extension for Visual Studio Online of a Time Ticker",  "provider": {    "name": "Gordon Beeming"  },  "baseUri": "https://localhost:44300/",  "icon": "https://localhost:44300/images/some-icon.png",  "contributions": {    "vss.web#hubs": [      {        "id": "time",        "name": "Time",        "groupId": "home",        "order": 22,        "uri": "index.html",        "usesSdk": true,        "fullPage": false      }    ]  }}

#Get the SDK

Navigate to GitHub to the samples project and grab the VSS.SDK.js file. Save a copy of that to a scripts folder inside a sdk folder and add it to your project.

Visual Studio Solution Explorer showing VSS.SDK.js file in sdk/scripts folder
Visual Studio Solution Explorer showing the VSS.SDK.js file added to the project under sdk/scripts.

#Include our App js files

While we here let's build the project, show hidden folders and add the app.js and app.js.map files to the project

Visual Studio Solution Explorer with Show All Files enabled, showing app.js and app.js.map
Visual Studio Solution Explorer with Show All Files enabled, displaying app.js and app.js.map.
Visual Studio Solution Explorer after including app.js and app.js.map in the project
Visual Studio Solution Explorer after including app.js and app.js.map in the project.

If you are using source control you should also at this point undo those files being added source control and then also add them to be excluded otherwise you may get a weird error when it comes time to build your project on a build server (TypeScript : Emit Error: Write to file failed...).

Visual Studio Team Explorer - Pending Changes window showing app.js and app.js.map
Visual Studio Team Explorer - Pending Changes window showing app.js and app.js.map files to be excluded from source control.
Visual Studio .tfignore file editor
Visual Studio .tfignore file editor, for excluding files from source control.

The reason we want these as part of the solution is so that when we do web deploy later they are deployed as well 🙂.

#Add our app icon

Make a images folder and add a image called some-icon.png to it

Visual Studio Solution Explorer showing some-icon.png in the images folder
Visual Studio Solution Explorer showing the some-icon.png file added to the images folder.

#Move App js file

Move your App.ts, App.js and App.js.map into a scripts folder. If you have source you might need to re undo and ignore those extra files.

Visual Studio Solution Explorer showing App.ts, App.js and App.js.map moved to the scripts folder
Visual Studio Solution Explorer after moving App.ts, App.js, and App.js.map to the scripts folder.

#Setup index.html

This is a rather simple step, replace the reference to app.js with one to sdk/Scripts/VSS.SDK.js so it will look something like

index.html showing VSS.SDK.js script reference
Updated index.html with VSS.SDK.js script reference.

Add the following script just inside your body tag

SDK initialization script
<script type="text/javascript">    // Initialize the VSS sdk    VSS.init({        setupModuleLoader: true,        moduleLoaderConfig: {            paths: {                "Scripts": "scripts"            }        }    });    // Wait for the SDK to be initialized    VSS.ready(function () {        require(["Scripts/app"], function (app) { });    });</script>

So at this stage your full index.html page will look like

index.html
<!DOCTYPE html><html lang="en"><head>    <meta charset="utf-8" />    <title>TypeScript HTML App</title>    <link rel="stylesheet" href="app.css" type="text/css" />    <script src="sdk/Scripts/VSS.SDK.js"></script></head><body>    <script type="text/javascript">        // Initialize the VSS sdk        VSS.init({            setupModuleLoader: true,            moduleLoaderConfig: {                paths: {                    "Scripts": "scripts"                }            }        });        // Wait for the SDK to be initialized        VSS.ready(function () {            require(["Scripts/app"], function (app) { });        });    </script>    <h1>TypeScript HTML App</h1>    <div id="content"></div></body></html>

#

#Update App.ts

In your App.ts file remove the window.onload function and replace it with it's body so your App.ts file will look like below

App.ts
class Greeter {    element: HTMLElement;    span: HTMLElement;    timerToken: number;    constructor(element: HTMLElement) {        this.element = element;        this.element.innerHTML += "The time is: ";        this.span = document.createElement('span');        this.element.appendChild(this.span);        this.span.innerText = new Date().toUTCString();    }    start() {        this.timerToken = setInterval(() => this.span.innerHTML = new Date().toUTCString(), 500);    }    stop() {        clearTimeout(this.timerToken);    }}var el = document.getElementById('content');var greeter = new Greeter(el);greeter.start();

#Run App

Running your app with ctrl + F5 you will get a blank app that does nothing 🙂

Blank app running in Internet Explorer
The initial blank app running in Internet Explorer.

Changed the url to point to the SSL version of your site just to make sure everything is working

App running with SSL in Internet Explorer
App successfully running with SSL in Internet Explorer.

Our App is now complete 😁

#Install your extension

If you have signed up for the private preview you should see a tab in the admin section of your account called Extensions like so

VSTS admin section showing Extensions tab
VSTS admin section with the Extensions tab visible.

Click Install, and then Browse 

Install extension dialog in VSTS
Install extension dialog in VSTS.

browse for your extension.json file

File open dialog browsing for extension.json
File open dialog to select the extension.json manifest file.

Click Open and then OK

Confirming extension installation in VSTS
Confirming the extension installation in VSTS.

Your extension is now installed

VSTS Extensions tab showing installed Time Ticker extension
VSTS Extensions tab showing the newly installed Time Ticker extension.

#View it on VSO

Go to a team project home page and you should now see a Time hub, click on it

VSTS project home page with Time hub
VSTS project home page displaying the new Time hub.

Once you land here you will the time 🙂

Time Ticker extension displaying the current time in VSTS
Time Ticker extension displaying the current time within VSTS.

That's 1 extension in the bag but having this run on your local machine is probable not want you would want because nobody else can see it.

#

#Publishing you app

You could buy an SSL certification but that costs a lot and most people don't have that kind of money laying around for fun apps and extensions so we'll turn to Azure. We will now right click on our project and click publish

Visual Studio right-click context menu with Publish option
Visual Studio right-click context menu on the project, with the Publish option highlighted.

If you setup an Azure site already you can import the publish settings but I haven't so I'm going to click on Microsoft Azure Web Apps

Visual Studio Publish Web dialog
Visual Studio Publish Web dialog with Microsoft Azure Web Apps selected.

and then click on New (again if you have a site already you can select it in this list)

Visual Studio Select Existing Web App dialog
Visual Studio Select Existing Web App dialog with New button highlighted.

Select a name and click Create

Visual Studio Create Web App on Microsoft Azure dialog
Visual Studio Create Web App on Microsoft Azure dialog, ready to create the new web app.

it will now take a small bit to setup your azure resource

Visual Studio Create Web App on Microsoft Azure progress dialog
Visual Studio Create Web App on Microsoft Azure progress dialog.

and then auto magically configure everything you need 🙂, click Publish

Visual Studio Publish Web dialog after Azure setup
Visual Studio Publish Web dialog after Azure Web App setup, ready to publish.

After the publish is finish your site will launch

Published app running in Internet Explorer via HTTP
The published app running in Internet Explorer, accessed via HTTP.

Something that you will notice is that this is http but and not https as we said earlier we require. So let's see what happens if we add a s in there 🙂

Published app running in Internet Explorer via HTTPS
The published app successfully running in Internet Explorer, accessed via HTTPS.

Everything still works 😁.

#Last bit of manifest changes

Now that we have a publicly accessible website running on https (for FREE) we can take that url and replace what we currently have in our manifest so it will now look like this

extensions.json (updated)
{  "namespace": "VSO-Time-Ticker",  "version": "0.0.2",  "name": "Time Ticker",  "description": "A simple extension for Visual Studio Online of a Time Ticker",  "provider": {    "name": "Gordon Beeming"  },  "baseUri": "https://vso-hello-world.azurewebsites.net/",  "icon": "https://vso-hello-world.azurewebsites.net/images/some-icon.png",  "contributions": {    "vss.web#hubs": [      {        "id": "time",        "name": "Time",        "groupId": "home",        "order": 22,        "uri": "index.html",        "usesSdk": true,        "fullPage": false      }    ]  }}

Re-install your extension

VSTS Extensions tab after re-installing Time Ticker extension
VSTS Extensions tab showing the Time Ticker extension after re-installation with the updated manifest.

and refresh your extension in VSO

Time Ticker extension running in VSTS, now served from Azure
Time Ticker extension running in VSTS, successfully served from the Azure Web App.

You will notice now that it obviously still works 🙂, if you close Visual Studio and it still works you know it working 🙂 and I suppose you can check fiddler for where it's reading the files from.

For more info on VSO Extensions visit http://aka.ms/vsoextensions.

A pretty neat getting started post is also on that site at https://www.visualstudio.com/en-us/integrate/extensions/get-started/visual-studio.

Microsoft has a project out on GitHub as well that is quite advanced in the API's that it uses and can be found at https://github.com/Microsoft/vso-team-calendar.

If you want a light overview over everything then you can get their VSO Extension Samples out on GitHub as well using the link https://github.com/Microsoft/vso-extension-samples.

Complete Sample code for this post is also out on Github at https://github.com/Gordon-Beeming/VSO-Time-Ticker

Gordon Beeming
Gordon Beeming

Father • Husband • Triathlete • SSW Solution Architect

Related posts