Continuous Delivery Right from Visual Studio: Creating a Continuous Delivery Pipeline using Continuous Delivery Tools for Visual Studio with Visual Studio 2017
Continuous Delivery is an essential part of modern software development and it is a must have, to deliver your software faster and more effectively to your clients. I remember just a few months’ back I got the opportunity to create a proper Continuous Delivery pipeline in my project and I had to spend quite some time to set things up on Visual Studio Team Services to get this up and running. Creating the continuous delivery pipeline was made much easier by the fantastic capabilities of Visual Studio Team Services, but still that took some time to set things up.
But now, you can quickly create a Continuous Delivery pipeline without ever leaving the comfort of Visual Studio literally just in minutes. Microsoft recently released Continuous Delivery Tools for Visual Studio 2017 and you can setup continuous delivery for your project right with in Visual Studio 2017. Before we start, you need to have Visual Studio 2017 installed in order to install the extension and get up and running. Let’s look at how to do this.
Open Visual Studio 2017 and in the menu bar and click on Tools > Extensions and Updates… menu item.
In the Extensions and Updates dialog box Expand Online section and Visual Studio Marketplace and search for Continuous Delivery Tools in the search box.
Then download and install the Continuous Delivery Tools for Visual Studio extension by clicking on Download button. You may be asked to close and re-open Visual Studio after the installation. After the restart, you will now be able to see a new Continuous Delivery Tools button added to the status bar of Visual Studio 2017. This indicated that the installation was successful.
Let’s create a new web application for Deployment on to Azure. Click on File > New> Projects… menu item in the menu bar and open the New Project dialog. In the Web section of the Visual C# templates, select ASP.Net Core Web Application (.Net Core) running on .Net Core.
Add an application name for the web application and click Ok to continue. In the next dialog box select the Web Application template from ASP.Net Core 1.1 templates and click OK to create the project
Now we have an ASP.Net Core Web Application, we can start creating the Continuous Delivery Pipeline for this Project. Here is where we start to use the Continuous Delivery Tools for Visual Studio extension. We have 3 ways of starting up the process.
- Click on the newly Added Continuous Delivery Tools button on the Status bar and Click Configure Continuous Delivery… menu item
- In the Menu Bar Click on Build > Configure Continuous Delivery… menu item
- Right Click on the Project in the Solution Explorer and on the menu, that opens, Click on Configure Continuous Delivery… menu item.
After clicking on the Configure Continuous Delivery menu item a new dialog box will open. Depending on if you have your code in Source Control or not, this dialog will be different. Since we didn’t add this project to Source Control the dialog box will ask us to add the project to Source Control and guide us through the process.
On the dialog box Click the Add this project to source control… link to get started. Now you will be asked to login to your Microsoft account that has access to Visual Studio Team Service to continue this process. After successfully logging in you will be taken to the Team Explorer panel in Visual Studio where you have an option to publish this project as a Git Repo to Visual Studio Team Services
Click on Publish Git Repo button to add the project to source control and push the repo to a git repository in VSTS. You will be taken to a new screen in the Team Explorer panel to select the Subscription (if you have multiple subscriptions), Team Service Domain (select the correct one if you have multiple domains) and finally a Repository Name.
Click on the Advanced link above the repository name text box to see more options. Here you can also select a VSTS Project that you can add the repository to. If you don’t want to select the VSTS Project, use the simple options and a new Team Services Project will be created with the same name as the Project name. Click on Publish Repository to publish the repository to VSTS.
After adding the project to source control in VSTS we need to again initiate the Configuration of Continuous Delivery. Using one of the 3 options we discussed earlier open Configure Continuous Delivery dialog box again. This time you will see that the dialog box is different.
Here you can see 2 sections, Repository and Branch to configure the repo and the branch you want to deploy from and Deployment Target section to configure the Azure Subscription and the App Service details. Both is these sections are pre-populated with details associated with the project and the repository that we just created.
Make sure you have the correct Microsoft account and Subscription selected, if you have multiple branches in the repository you can also select the correct branch you want to deploy. If you want more options to configure the App Service resource click on the Edit.. link alongside the App Service input box.
The Edit App Service dialog box will open, here you can add a new name for the App Service, Select an App Service Plan from existing service plans, select the Location to deploy the application and select an already existing Resource Group to do the deployment. (If the default settings are used a new Resource Group will be created with the same name as the project name and the app service name will also be the project name). Click Ok to accept the changes.
Finally, after the configurations are done click Ok on the Configure Continuous Delivery dialog button to initiate the creation of the Continuous Delivery Pipeline. This will take few minutes to complete. You can see the progress in the Output Window under Continuous Delivery Tools output source.
After the deployment completes the output window will have links to the Build Definition and the Release Definition on Visual Studio Team Services and App Service Resource on Azure Portal. Also, if you hover over the new button added to the status bar, you will see the details about the last deployment. If your deployment fails it will also be indicated in this status bar.
Let’s go and look at what the Continuous Delivery Tool for Visual Studio built for us behind the scenes. If you click on the for the Build Definition, you will be taken to the build definition created for the project.
You can see that it has created a build definition for us for our ASP.Net Core Web Application. And it has already complete the first build and used that build artifacts to deploy the application to Azure App Service. If you navigate to the Releases in VSTS you can see the Release Definition created for us.
It contains an Azure App Service Deploy task included to release the application to Azure App Service. Finally, if we navigate to the app service URL that was created we can see the ASP.Net Core web application that we create is now hosted in Azure.
As you can see by now, Continuous Delivery Tools for Visual Studio has made it easy to create a Continuous Delivery pipeline without ever leaving Visual Studio 2017. And the best thing is it only take a few mins to do so.
Yes, this is a simple pipeline which contains a build definition and a release definition with the minimal VSTS tasks included to get you up and running. But this can be a great starting point to customize and create your own pipeline for more complex applications with many other build and release tasks included. Continuous Delivery Tools for Visual Studio is a great addition to the Visual Studio ecosystem in my opinion and I’m sure you will find it useful as well.
You Might Also Like
← Previous Post
Design Patterns for Cloud: #1 Federated Identity Pattern
April 10, 2017