Walkthrough–Add Azure Web App to Visual Studio Team Services


Overview

In this walkthrough I will show  you how to use Visual Studio Team Services with an existing Azure App Service project (specifically an Azure Web App).  We will add a task to update/create the project database from a DACPAC file and enable CI (Continuous Integration).

Sign up for Visual Studio Team Services 

Go to: https://www.visualstudio.com/team-services/   There is a link at the bottom to use the cloud services for free!  Sign up to start using Visual Studio Team Services with your development projects.

Use the same login you use for logging into Visual Studio and the integration will allow you to easily sync your projects to Visual Studio Team Services.

Add your project to the Visual Studio Team Services from Visual Studio 2017

Open Visual Studio and your existing project.  The bottom right of the IDE you will see the  ‘Add to Source Control’ menu:

capture20170717092329860

NOTE:  In Visual Studio 2015 the menu item is ‘Publish’.  This will publish a Git Repo with the name of your project for you.

Choose ‘Git’:

capture20170714144019299

 

Once you have done this, a Repo is created on your local machine that will allow you to develop and track your changes.  You can save your changes often to this local Repo so that if you make a mistake, you can easily back out your changes and revert to an older version.  Once you are ready to publish these changes for others to use you can Publish the Git Repo to Visual Studio Team Services.  This will allow others to work on the same project at the same time, and then use the tools to merge the work you are all doing into a single master branch, ready to publish.

Initial Publish Git Repo to Visual Studio Team Services (select the Publish Git Repo button):

capture20170718085313452

Give your Repo a name or use the default which will be the project name and push ‘Publish repository’:

capture20170718090059374

You can click on the hyperlink to see the files up in Visual Studio Team Services:

capture20170718090305819

capture20170718090438193

When you are developing and you hit a milestone you should Sync your changes to the local Git repo.  In this case I added a default.aspx page and you can see it is marked with a ‘+’ to indicate it is a new item added and the solution has a red check indicating it has changed:

capture20170718090735697

Another indicator is the pencil icon in the lower right side if the IDE.  It indicates there are 4 changes.  Click on that icon, and you will see the Changes panel of Team Explorer.  Enter a commit message and click the ‘Commit All’ button:

capture20170718091221482

You will see the Commit is created local, and it gives you an option to Sync up to VSTS (Visual Studio Team Services).  You can also see the up arrow icon at the bottom of the IDE indicates there is ‘1’ Commit local that has not been pushed up to VSTS as of yet.

capture20170718091305021

When you are ready to share your changes up on VSTS you can hit the commit icon (up arrow at bottom) or choose the Sync link and push your changes to VSTS.  Choose the ‘Push’ link to push the Commit:

capture20170718091618722

And again you can go to VSTS and see the added files:

capture20170718091838003

Publish from Visual Studio Team Services

Once you are ready to deploy your changes, ensure you have an Azure Web App Resource already defined to in the Azure Portal to deploy to.  Then you can build and deploy your code from VSTS to your Azure Web App.

Click on the ‘Build & Release’ tab in VSTS and since you have no build definitions create a ‘New definition’:

capture20170718092320857

Select and Apply the Azure Web App template:

capture20170718092407872

Fill in all the required information.  Note that you must Authorize and add your credentials to be able to access the subscription and App Service:

capture20170718092539696

Note the Default agent queue should be Hosted, or Hosted VS2017.  I chose the latter because my project is a VS2017 solution:

capture20170718092651972

Choose ‘Save & queue’ and optionally add some text to the ‘Commit’ field and press the ‘Queue’ button:

capture20170718092719872capture20170718092753465

This will queue the build and release for you.  Clicking on the link for the build (or going to history) will allow you to monitor the progress on the console view:

capture20170718092807848 capture20170718092846066

Update a Database from your Project

Now that we know the build and release cycle is working properly, we will add a DACPAC file to update the database during the build and release Task.  I will leave it to you to ‘Bing’ how to create a DACPAC file.

Once you have the DACPAC, you want to add it to your solution:

Create a folder in the root of your solution called ‘App_Data’.  The name of this folder is very important as we will use this to exclude this folder in the Build process from being pushed out to the application:

capture20170718094431737

Locate the DACPAC file and add it to the App_Data folder choosing ‘Add, Existing item…’:

capture20170718095418790

Then commit these changes and push it to VSTS as you did above for Default.aspx.

Modify the Build in VSTS to exclude the DACPAC file from the release to the App Service

In VSTS click on the ‘Build & Release’ tab and select the Build Definition we created.  Then click the ‘Edit’ icon on the top right of the view:

 

capture20170718095806304

Click on the ‘Azure App Service Deploy…” step of the process and open the ‘Additional Deployment Options’ and select the option to ‘Exclude Files from the App_Data Folder’.  Remember that is the folder we put the DACPAC file.  There is no need to deploy that file to the Azure Web App because we are going to add a step to update the Database from the Build/Release again in VSTS.

capture20170718100024458

 

Add a Task to the Build Definition to Update the Database from the DACPAC file

capture20170718100757786

Fill in the required fields and change the Azure Connection Type to ‘Azure Resource Manager’ and then Authorize using your subscription (as you did before)

capture20170718125746442

You can get the server name from the Azure Portal by looking up you database the (it is in the Overview):

capture20170718130031575

And fill in the rest of the information:

capture20170718130305679

Finally select the DACPAC file from the path of you repository by hitting the ‘…’

capture20170718130533621

Hit ‘Save and Queue’ again and Queue this build

At this point I got an error!

capture20170718130729625

This is complaining that the Hosted VS 2017 agent does not support sqlpackage (that is all I added).  The fix is to edit the build again, click on the top Process tab on the left side and set the ‘Default agent queue to ‘Hosted’.

capture20170718131041207

Save and queue, and click on the build link as before to see the results and you will see the SQL Task:

capture20170718132331556

 

Enable CI

For my example I want to have VSTS build and release to my Azure Web App whenever someone pushes changes in the Master branch.  See the VSTS site for more options and examples.

This is as simple as Editing the Build definition again and navigating to the Triggers section.  Here you simply choose to Enable the trigger, use the defaults and Save the Definition:

capture20170718133247128

 

Conclusion

I hope this Walkthrough helps you set up your first Azure Web App using Visual Studio Team Services.  Of course there are other ways to do what I showed you here, but this will get you started.

Additional Links

https://www.visualstudio.com/team-services/

https://www.visualstudio.com/learn-git/


Comments (0)

Skip to main content