Skip to content
Richard Kerslake By Richard Kerslake Engineer I
How to package a web project for deployment from the command line

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.

The best hour you can spend to refine your own data strategy and leverage the latest capabilities on Azure to accelerate your road map.

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:

Azure Weekly is a summary of the week's top Microsoft Azure news from AI to Availability Zones. Keep on top of all the latest Azure developments!

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.

Richard Kerslake

Engineer I

Richard Kerslake

Richard 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 customers, who are seeking to take advantage of Microsoft Azure and the Cloud.

Richard worked at endjin between 2014-2017.