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.

Sample Web Application and Parameters.xml
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.
Build Definition
If you create a new Build Definition you can select the Visual Studio build template for this example:

Create new build definition – Visual Studio template
The next screen allows you to select your repository source and then click on Create

Create new build definition – Repository source
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:

Visual Studio Build Task – MSBuild Arguments
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation=$(build.artifactstagingdirectory)
26-SEPT-2017: MSBuild Parameters Updated to fix an error
Here is the Publish Build Artifact task/step that copies the Web Deploy Pacakage files created by the Visual Studio Build step.

Publish Build Artifact
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.

New build definition – Web Deploy Package
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

Build – Artifacts Explorer
Here is what the contents of the *.SetParameters.xml file looks like:

Contoso.Web.SetParameters.xml
Release Definition
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

Create new release definition
Select Empty and click Next

Choose a source that publishes the artifacts to be deployed
Click Create and you will be brought to your release definition

New Empty 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)

Release Management | Environment | Add tasks
Add the Tokenize with XPath/Regular expressions to your Release Definition

Configure Tokenizer Utility task
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.

Tokenizer: Transform Source Filename
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.

Add tasks | Deploy | Azure File Copy
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.

Azure File Copy | Source | Select File Or Folder
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.

Azure VMs File Copy
Now we can add the WinRM – IIS Web App Deployment task

Add tasks | Deploy | WinRM – IIS Web App Deployment
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.

Deploy IIS App
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.
How about multiple projects deployed as web applications under same website?
LikeLike
That is not a problem, the “IIS Web Application Name” parameter is the IIS path where you want to deploy your web application. This can include a value such as “Default Web Site/Contoso.web_deploy”, this is specified in the Deploy IIS App task under Deployment | Website Name.
Hope that helps.
Wes
LikeLike
Thanks for the tutorial, I’ve got everything almost working except I’ve spent a good portion of the day fighting a problem. When it gets to the deploy IIS App step I get an error “Error: A value for the ‘setAclUser’ setting must be specified when the ‘setAcl’ provider is used with a physical path” The application I am trying to deploy will be deployed to the root of the website. I think it has something to do with the setting for IIS Web Application Name. Before I tried to tokenize everything it worked using the default settings file generated by MSBuild but now trying to specify everything in the parameters.xml file, this failure occurs. Any ideas?
LikeLike
Hi Joey,
There was an error in the MSBuild parameters, I updated the post to only have the following:
/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:PackageLocation=$(build.artifactstagingdirectory)
My apologies for the late reply and the error.
Wes
LikeLike
Can this be done without access to WinRM configuration (i.e. shared hosting)?
LikeLike
Thank yyou
LikeLike