I’ve spent quite a bit of time working with WebDeploy and Release Management lately for some clients. You should also be aware of the new tasks that were added to the Visual Studio Marketplace recently:
The extension helps manage the following in IIS:
- Create a new website or update an existing website.
- Create a new application pool or update an existing application pool.
- Deploy a Web Application to the IIS Server using Web Deploy**
The extension makes it so easy to deploy your web application vs. rolling your own PowerShell script.
** It should be noted there are a few caveats to this particular task as to what it will and won’t do. If you need skip a folder from being deleted or take the app offline then you need to use the msdeploy command (via remote PowerShell). I’ll show some examples later on where I explicitly define those options on the command-line.
Let’s assume you already have a Web Application you wish to publish and that you have some Application Settings, Connection Strings to set during your publish. We’ll then configure a build definition and release.
My Sample Web Project
Here is a sample Web Application with a parameters.xml file with some settings that we will change for specific deployments in the release pipeline.
If you want to define a database connection string in this Parameters.xml file you can, by default the database connection strings and IIS Web Application Name are automatically added to your SetParameters.xml file during the packaging process in VS but you are able to override this behaviour if you’d like control over all of the settings.
Here is an example snippet of a connection string from the parameters.xml:
<parameter name="ESB-Web.config Connection String" description="ESB Connection String" defaultvalue="__ESB__"> <parameterentry scope="\\web.config$" type="XmlFile" match="/configuration/connectionStrings/add[@name='ESB']/@connectionString"> </parameterentry> </parameter>
NOTE: The name attribute of the parameter has -Web.config Connection String appended to the name of your connection string, this is intentional and is required.
You’ll also notice in the above parameters.xml file that all the values specified for the attribute defaultvalue are named as __[name]__ these will be replaced during the release process using a task.
If you create a new Build Definition you can select the Visual Studio build template for this example:
The next screen allows you to select your repository source and then click on Create
After selecting Create you will edit the following build steps
- Build solution **\*.sln
- Copy Files to: $(build.artifactstagingdirectory)
- Publish Artifact: drop
Here are the MSBuild Arguments that are specified in the Visual Studio Build task/step field MSBuild Arguments:
Here is the Publish Build Artifact task/step that copies the Web Deploy Pacakage files created by the Visual Studio Build step.
If you created a new build definition your build steps should resemble the following image below. Note: I deleted the Copy files to… build step from the template in this example, it is not required because in the MSBuild arguments above we’re specfying the PackageLocation as $(Build.ArtififactStagingDirectory) which is used by the Publish Artifact: Web Deploy step to get our files. I’ve specified the Artifact Name as Web Deploy.
Save your Build Definition by clicking Save in the toolbar and then select Queue build… to test out the generation of your Web Deploy Artifacts.
If your build is marked as failed because of the Test Assemblies build step, fix your tests or edit the Test Assemblies step Control Options and select Continue on error to have your build marked as Build Partially succeeded.
If you trigger a build you can take a look at the Web Deploy Artifacts that are generated
Here is what the contents of the *.SetParameters.xml file looks like:
If you were able to view the Web Deploy Artifacts in the Artifacts Explorer produced by your build, navigate over to the Release tab by clicking on Release.
Click the large green plus sign under the Explorer to create a new release definition
Select Empty and click Next
Click Create and you will be brought to your release definition
We need to get an extension from the VisualStudio Marketplace which has a Tokenizer task to replace the tokens in the SetParameters.xml file that is part of our build artifacts. Here is a screen capture and link to the Release Management Utility tasks extension by Microsoft DevLabs
If you are using Visual Studio Team Services (VSTS) click Install or Download for TFS 2015 Update 2 or higher to add it to your Team Project Collection. I’m not walking through those steps but once the tasks are added to your collection you can select the required task (shown below)
Add the Tokenize with XPath/Regular expressions to your Release Definition
You will be brought back to your list of Tasks for the environment. If we check the documentation in the VSMarketplace for this task we know that the task will find the pattern
__<pattern>__ and replaces the same with the value from the variable with name
<pattern>. The destination filename and configuration Json filename fields are optional.
You will notice the menu options have changed in my screenshots as I have started using the new interface on VSTS to finish the post.
We will need to copy our WebDeploy package to the VM and so we need to click Add Tasks and select the Azure File Copy task, if you are doing this on-premises you would select the Windows Machine File Copy task.
You need to complete several fields for the Azure File Copy task. For the location I have selected the artifact that was created by the build linked to my release.
In the example above I am targetting Azure VMs, Classic storage account and a Cloud Service. The Admin login and password are written in the task as variables and they are created under the variables tab. The destination folder I have entered c:\temp . You also have a checkbox to select if you want to Clean Target (delete the files in the destination before the copy). I have chosen Test Certificate so I can use WinRM over HTTPS and Copy in Parallel as I have two machines in an Availability Group behind the Cloud Service.
Now we can add the WinRM – IIS Web App Deployment task
If you want to configure IIS before you do a deploy of the webdeploy package you can add the WinRM – IIS Web App Management task to manage the website and Application Pool settings.
Here is the task filled out and we’re ready to roll! If I am targetting more than one machine I can specify multiple machines comma separated with ports opened for WinRM connections.
If you have any questions please feel free to leave a comment. I encourge you to check out all the awesome free and paid extensions on the Visual Studio Marketplace to help you extend your VSTS/TFS environment.