Endjin - Home

How to package a web project for deployment from the command line

by Richard Kerslake


If you are trying to create a package to deploy a web project from the command line using msbuild, you might be struggling with the required arguments.

Simply specifying /target:package is not enough. While this will generate a zipped web package, it will only include direct references from the web project itself. Any projects the web project references will likely have it’s own packages as well, and these transitive dependencies will not be included.

One possible way to get around that is to add all the packages necessary to your web project, including those that are really just transitive dependencies.

A better way is to use some of the newer project-level properties provided in VS2012+ – hopefully you are on the latest VS2015 anyway!

To generate this web deploy package we can use msbuild with the following arguments:





This will produce a package that includes all of the required dlls. The package can be used as part of an automated continuous integration / continuous deployment pipeline.

A brief explanation of the various msbuild arguments:

  • “DeployOnBuild” tells msbuild that this web project needs to be packaged/deployed as part of the build.
  • “WebPublishMethod” ensures we are just creating a deployment package. There are other options like publishing to the file system or elsewhere using MSDeploy.
  • “PackageAsSingleFile” will zip up the output into a single file.
  • “PackageLocation” is where the zip will be saved.

An aside on deploying the web package using Azure Resource Manager

The modern way of deploying to Azure is to use Azure Resource Manager (ARM) templates.

To do this, the ARM template can contain a web site resource, which itself contains an MSDeploy resource.

A sample MSDeploy resource from an ARM template:

 "name": "MSDeploy",
 "type": "extensions",
 "location": "[resourceGroup().location]",
 "apiVersion": "[variables('apiVersion')]",
 "dependsOn": [
 "[concat('Microsoft.Web/sites/', parameters('webAppName'))]"
 "properties": {
 "packageUri": "[concat(parameters('_artifactLocation'), '/', parameters('webDeployPackagePath'), '/', parameters('webDeployPackageFileName'), parameters('_artifactLocationSasToken'))]",
 "dbType": "None"

Also see this template from the Azure Quickstart Templates repository on GitHub for a larger sample.

This JSON snippet includes a packageUri property that has to be an accessible URL e.g. to a web deploy package in Azure blob storage accessed using a SAS token.

Once the package has been generated using the appropriate msbuild arguments outlined above, it can be uploaded to blob storage and referenced in the MSDeploy step of the ARM template. The Azure Storage PowerShell cmdlets could be used for doing this upload.

About the author

Richard is a Software Engineer and certified Microsoft Cloud Platform developer, providing strategy, insight and engineering services. He has a background in financial services, working on large scale distributed trading systems. Richard has a passion for delivering real business value to endjin’s clients, who are seeking to take advantage of Microsoft Azure and the Cloud. You can follow Richard on Twitter.