I have an Azure Cloud service which consists of web and worker roles. To make it quicker to update the cloud service whenever I’ve made changes to it, I want to deploy it from Visual Studio Online.
I already use VSO for source control for this project, and I have previously used the XAML based build process in VSO. Since I was going to move the project from one Azure account to another (from my play/test account to the business account), I decided to change the build process.
Visual Studio Online build.vnext
The new build system is still in preview and has some rough edges. I have encountered bugs regarding rendering of the build output in the browser and queued builds not starting. However, I still think it is ready for production use.
I’ve previously covered how to install and set up an on-premises build agent.
In Visual Studio Online, the build system is accessed from the BUILD menu. The explorer view on the left has been changed a little, ot it now has Build definitions as well as XAML definitions. The XAML definitions are the old style build “scripts”.
There is no change to what you can do with the XAML build definitions; you can still see them and queue builds as usual. Editing build definitions is done in Visual Studio.
With the new build system, the build definitions are created and edited online in VSO.
A build definition consists of a number of build steps. There are many pre-defined build steps that you can choose from: Visual Studio Build, msbuild, Ant, Maven, Xamarin Test Cloud, and many more.
If the pre-defined build steps don’t suit you, you can run PowerShell, Batch, and Bash shell scripts also. In fact some of the pre-defined build steps are simply PowerShell scripts with parameters that are filled in from the VSO web interface.
Build and publish to Azure
After some trial and error, I finished up with a script like this:
The script builds the solution and runs all tests.
I haven’t actually configured the Publish symbols action, but would do that if this were not a web site, so we could easier debug any exceptions.
The added MSBuild task runs MSBuild with the the Publish build target.
This is a target that is already present in an Azure Cloud Service project. It packs the service into a .cspkg file that can be uploaded to Azure for deployment.
The final step in the build definition is Azure Cloud Serivce Deployment expects a .cspkg as well as the .cscfg file from the cloud service project.
In the Azure Cloud Service Deployment build step youneed to select which Azure subscription to use. The Azure subscriptions that are available need to be configured first by adding Service Connections in the VSO project. The Manage link from the build step settings takes you straight to the Service Connections page.
You need the management certificate and other details from the Azure publishsettings.xml file.
I have configured a variable called AzureDeploymentSlot in the build definition. It is used to let the person starting the build select which deployment slot to use. The build definition variables are referenced using $(variablename) .
In addition to the user defined variables, there is a long list of predefined ones. The user defined and predefined variables can be edited and listed from the build definition’s Variables page:
It took me a few trial runs to get the paths to the .cspkg and .cscfg right, but the VSO build logs are helpful by showing the console output from the build process in almost real-time.