In this lab, you will create a Visual Studio Team Services online account, check in your code, create a Continuous Integration pipeline, and test your cloud-based application.
In this hands-on lab, you will learn how to:
- Create a Visual Studio Team Services online account.
- Create a VSTS Git repository.
- Add your code to the VSTS Git repository.
- Create a Continuous Integration pipeline.
- Deploy a built application to an Azure Web App from VSTS.
- The source for the starter app is located in the start folder.
- There will be no code changes required so the the end folder will remain empty.
- Deployed the starter ARM Template HOL 1.
- Completion of the HOL 3.
Note: If you did not complete the previous labs, the project in the start folder is cumulative. But you need to add the HOL 2 and HOL 3 settings to the
Web.config
file.
This hands-on-lab has the following exercises:
- Exercise 1: Create VSTS online account
- Exercise 2: Create VSTS Git repository
- Exercise 3: Add application to VSTS Git
- Exercise 4: Create a Continuous Integration pipeline
- Exercise 5: Deploy code to an Azure Web App
-
In your browser, navigate to https://www.visualstudio.com/
-
Click
Get started for free
link belowVisual Studio Team Services
. -
Log in with your Azure AD account.
-
You will be asked to choose an hosting address and if you want to use Git or Team Foundation Version Control. Select
Git
and clickContinue
. -
A new project called
MyFirstProject
will be automatically created.
VSTS gives us the option to use Git or TFVC as our project's repository. For this exercise we will use Git, and then clone the repository to our dev machine.
Note that if you acquired these lab materials via a
git clone
of the workshop repo then you should select a folder somewhere else on your dev machine. This will minimize conflicts between the two separate repositories.
-
We will ignore the automatically created
MyFirstProject
. Starting at your TFVC account's landing page, clickNew Project
. -
Enter a project name such as DevCamp, ensure
Version control
is set toGit
and then clickCreate
. -
Wait for the project to be created. This process may take up to 60 seconds. When finished you will be redirected to the project page
-
Click
Dashboards
and explore your pre-built dashboard. Familiarize yourself with the variety of widgets available, and the customization options.
You have now created a project in VSTS with a Git repository. Next we'll clone the repository locally to your developer machine and upload code from our machine to VSTS.
-
Click
Code
on the top toolbar to navigate to the Code screen. -
Click the
Clone in Visual Studio
button.Note if you are using Chrome, you may receive a pop-up message. The Clone in Visual Studio option uses a custom protocol handler to open in the client. Select
Launch Application
.The Internet Explorer will display a security warning. Click
Allow
to continue: -
When Visual Studio launches, you will be prompted in the
Team Explorer
window to create a local folder to clone into. Select the...
next to the local address: -
Create a new local folder outside of the GIT folder you have been using for the other HOLs. In the example below, the folder was created as
DevCampVSO
: -
Click
OK
andClone
. -
Open Windows Explorer and copy the files from the
start
folder in this HOL and copy the contents into the folder you created above. -
Open the copied solution file in Visual Studio.
-
Ensure the
Utils
->Web.config
settings are set to the values for your application (you can copy them from your working copy back from HOL 3).<!--HOL 2--> <add key="INCIDENT_API_URL" value="API URL" /> <add key="AZURE_STORAGE_ACCOUNT" value="STORAGEACCOUNT" /> <add key="AZURE_STORAGE_ACCESS_KEY" value="STORAGEKEY" /> <add key="AZURE_STORAGE_BLOB_CONTAINER" value="images" /> <add key="AZURE_STORAGE_QUEUE" value="thumbnails" /> <add key="REDISCACHE_HOSTNAME" value="" /> <add key="REDISCACHE_PORT" value="6379" /> <add key="REDISCACHE_SSLPORT" value="6380" /> <add key="REDISCACHE_PRIMARY_KEY" value="" /> <!--HOL 3--> <add key="AAD_APP_ID" value="" /> <add key="AAD_APP_SECRET" value="" /> <add key="AAD_APP_REDIRECTURI" value="" /> <add key="AAD_INSTANCE" value="https://login.microsoftonline.com/{0}/{1}" /> <add key="AAD_AUTHORITY" value="https://login.microsoftonline.com/common/" /> <add key="AAD_LOGOUT_AUTHORITY" value="https://login.microsoftonline.com/common/oauth2/logout?post_logout_redirect_uri=" /> <add key="AAD_GRAPH_SCOPES" value="openid email profile offline_access Mail.ReadWrite Mail.Send User.Read User.ReadBasic.All" /> <add key="GRAPH_API_URL" value="https://graph.microsoft.com" />
-
On the Team Explorer tab, select the changes view by clicking on
Changes
. You may be prompted to confirm your user name. -
In the changes view, you will see a list of changes that are ready to commit to the local repository. In our case it will be the copied solution.
If you made changes to the files, and you do not see them in the list, ensure that you have cloned the repository from the repo.
cd\DevCampVSO Git init Git commit * Git push origin master -m ‘initial commit’
-
Right click on the top level folder and select
Stage
: -
Enter a comment for the check-in and click
Commit Staged
. Not that the comment is mandatory and the button becomes active only after you have entered a comment. -
Because Git is a distributed source control system, the changes we commit are not visible to anyone else. Making our changes visible will require that we synchronize the repositories. This process is both a Git Pull (to receive changes from the remote repo to your local repo) and a Git Push to send changes from the local repository. We will perform a sync to pull the changes and push our changes. Click
Sync
in the commit message. -
On the next screen, we will push our changes to the server. Since this is the first check-in, there are no incoming commits. Click the
Push
link belowOutgoing Commits
. -
In your browser, navigate to the Visual Studio Team Services site and view the committed files.
-
If you want to return to the changes view of the Team Explorer to stage more commits, click the headline to open a drop-down of all the views.
With application code now uploaded to VSTS, we can begin to create builds via a Build Definition. Navigate to the Build
tab from the top navigation. We will use the hosted agent within VSTS to process our builds in this exercise.
-
From the
Build & Release
tab, create a newBuild Definition
by clicking theNew Definition
button: -
There are prebuilt definitions for a variety of programming languages and application stacks. For this exercise select
.NET Desktop
and clickApply
: -
The build tasks are created for us as part of the template.
-
On the
Get sources
step set theFrom
value to your VSTS Project and theRepository
to the repo that was earlier created. -
Navigate to the
Build Solution
step. Add the following in theMSBuild Arguments
text box to create a web deployment package as part of the build:/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="bin\deploymentpackage"
-
In the build step
Copy Files to: $(build.artifactstagingdirectory)
, the default setting uses build definition folders. We are not using custom build configurations so we need to update the contents value.**\bin\**
-
Click
Save & queue
. Our saved Build Definition is ready to be processed by the Hosted Build Agent. -
Accept the defaults and click
Queue
. Your build will then be queued until the Hosted Build Agent can pick it up for processing. This typically takes less than 60 seconds to begin. -
Once your build completes, click each step on the left navigation bar and inspect the output.
Note: If your build fails go back to Visual Studio and make sure the solution can be build. Make any neccessary fixes and commit the changes by staging the changes, synchronizing and pushing.
-
Let's inspect the output artifacts that were published. Click the
Build XXX
header in the left pane to view the build's landing page. -
Select
Artifacts
from the horizontal toolbar. -
A
drop
folder has been created containing the compiled output. ClickExplore
to see them. -
Expand the
drop
folder and view the build artifacts. ClickClose
when complete. -
Click
Download
next to thedrop
folder to save the build locally. -
Unzip
drop.zip
to see the application files created by the build agent. This artifact will be deployed to an Azure Web App in a later exercise.
We now have a Build Definition that will compile the application and create a package for deployment anytime code is checked into the repository, or a manual build is queued.
In the ARM Template that was originally deployed, a web app was created as a development environment to hold a deployed .NET application. We will use this web app as a deployment target from VSTS. First, we need to prepare this web app for our application code.
-
Visit the Azure Web App by browsing to the Azure Portal, opening the
DevCamp
Resource Group, and select the Azure Web App resource that begins withdotnetapp
before the random string. -
Once the blade expands, select
Browse
from the top toolbar: -
A new browser tab will open with a splash screen visible:
-
Now that we have a build being created and a website to deploy into, let's connect them. In VSTS, navigate to the
Build & Release
tab. -
Click on
Releases
. -
Click the
+ New Definition
button to create a new release definition: -
Select
Azure App Service Deployment
and clickNext
. -
Ensure the
Source
is set to the Build Definition name used in the earlier exercise and thatQueue
is set to theHosted
option. Then clickCreate
to finish creating the Release Definition. -
We need to connect your VS agent with your Azure subscription so it can deploy resources. If the drop-down next to
Azure subscription
offers you your subscription, select it, authorize it and continue to select yourdotnetapp...
Azure Web app resource from theApp Service name
drop-down. -
If the drop-down next to
Azure subscription
does not offer you your subscription or the drop-down next toApp Service name
does not offer you your Azure Web app resource (give it a moment after selecting the subscription), click onManage
: -
This will open a screen where you can connect to the ARM service endpoint. Select
New Service Endpoint
->Azure Resource Manager
. -
Provide a connection name and select your subscription then click
OK
.If your subscription is not in the dropdown list, click the link at the bottom of the window, and the window format will change to allow you to enter connection information on your subscription:
-
Another option is to create a service principal. The steps to create a service principal is below.
If you have not created a service principal for the subscription, you will have to follow the instructions to do so. This process will provide the information to enter in this dialog:
-
Open this PowerShell script in your browser. Select all the content from the window and copy to the clipboard.
-
Open a PowerShell ISE window. In the text window, paste the PowerShell script from the clipboard.
-
Click the green arrow to run the PowerShell script.
If the PowerShell gives an error at runtime regarding a missing AzureRM module, please install it by executing the following command in a PowerShell window with admin privileges:
Install-Module AzureRM
. Then runSet-ExecutionPolicy RemoteSigned -Scope process
to adjust the execution level -
The PowerShell script will ask for your subscription name and a password. This password is for the service principal only, not the password for your subscription. So you can use whatever password you would like, just remember it.
-
You will then be asked for your Azure login credentials. Enter your Azure username and password.
The script will print out several values that you will need to enter into theAdd Azure Resource Manager Service Endpoint
window. Copy and paste these values from the PowerShell window:- Subscription ID
- Subscription Name
- Service Principal Client ID
- Service Principal Key
- Tenant ID
-
Also, enter a user-friendly name to use when referring to this service endpoint connection.
-
Click
Verify connection
, and ensure that the window indicates that the connection was verified. Then ClickOK
andClose
. -
If this is the first time you are connecting to this subscription, you will need to authorize VSTS to have access to deploy to Azure. After you select your subscription, click
Authorize
.
-
-
Navigate back to the VSTS build tab in the browser and click the click the
Refresh
icon to refresh the connections. TheAzure
connection that we setup should now appear. Select it. -
Next, for
App Service Name
choose the name of the .NET Azure Web App. It may take a moment to populate. -
From the menu bar select
Save
to save the Release Definition, and selectRelease
->Create Release
. -
Enter the release information and select the build to deploy. Ensure that the latest successful build is selected from the drop-down box. Click
Create
. -
Click on the release number in navigation header. This will allow you view the current release information.
-
After a successful build you should see the application deployed to your web app.
-
Update the application configuration to match the current settings you have deployed. Copy the values from the
Web.config
to the Application configuration in Azure if they do not match. Open the Azure portal and find the .NET web application. -
Open the Application Settings.
-
Copy the values from the
Web.config
into the application settings. If you do not have values for these settings, please review the previous labs for the correct values. -
Click
Save
. -
Navigate to the Application Registration Portal.
-
Open the configuration for your application and add the Azure web application URL to the list of Redirect URLs. Click
Save
.Note: Be sure to include the trailing slash / in the URL and ensure this address is using https.
-
Open a browser and navigate to the site. You should see the running site on Azure.
If your browser displays the error
Could not load file or assembly 'System.IdentityModel.Tokens.Jwt' [...]
you have to downgrade the NuGet packageSystem.IdentityModel.Tokens.Jwt
to 4.0.3 in Visual Studio.
In this hands-on lab, you learned how to:
- Create a Visual Studio Team Services online account that you used for version control of your code, automatic compiling and deploying of your web app.
- Create a VSTS Git repository that you utilized to synchronize your source code on your machine and in the cloud.
- Add your code to the VSTS Git repository.
- Create a Continuous Integration pipeline that you used to automatically compile your application and create packages for deployment anytime code is checked into the repository.
- Deploy a built application to an Azure Web App from VSTS and thus automating the final steps of your deployment process.
After completing this module, you can continue on to Module 5: ARM.
View Module 5 instructions for .NET.
Copyright 2016 Microsoft Corporation. All rights reserved. Except where otherwise noted, these materials are licensed under the terms of the MIT License. You may use them according to the license as is most appropriate for your project. The terms of this license can be found at https://opensource.org/licenses/MIT.