How to: Use MSBuild to Create a Web Package

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

If you want to automate creating Web packages from your Web application projects, you can use the MSBuild tool. MSBuild.exe is a command-line executable that you can use to create Web packages.

Many development teams automate their build process to create more predictable builds, to save time compared to creating builds manually, and to provide early bug detection with Build Verification Tests (BVTs). Using MSBuild to automate the build process can save time and make the build process more predictable. 


The Web packaging and deployment feature in Visual Studio 2010 uses MSBuild to build and deploy Web application projects. For more information about MSBuild, see MSBuild.

You can set properties for Web packaging using MSBuild by using the Publish tab in the Properties window of a Web application project. The Publish tab is actually a user interface to set MSBuild properties used in Web packaing. All properties that you set by using the Publish tab are saved in the csproj or vbproj file of the project.


Note that the properties can be specified for a particular configuration setting. You can specify different settings for each build environment, such as debug, test, staging, or production configurations.

You can also specify additional properties as command-line parameters by using MSBuild. Be aware that values that are passed by using the command line override values set in the Web application's project file. This enables you to store common property values in the project file, and override values if necessary during build and package creation time from the command line.  

Using MSBuild to create a Web package

To create a Web package using MSBuild from the command line

  1. Open the Visual Studio Command Prompt.

  2. Type the following at the command prompt:

    MSBuild "MyProjectName.vbproj" /T:Package
    MSBuild "MyProjectName.csproj" /T:Package

    The /T:Package parameter specifies the MSBuild Target named Package, which is defined as a Web package. If you do not specify the /T parameter then MSBuild builds the project instead of creating a package.

MSBuild requires that the project build successfully before creating the Web package, so that using MSBuild in an automated build environment will not create faulty Web packages.

Specifying a Configuration Setting

By default, MSBuild uses the Debug configuration when it creates a Web package. You can specify a configuration using the command line /P parameter.

To create a Web package using MSBuild and a configuration

  1. Open the Visual Studio Command Prompt.

  2. Type the following at the command prompt:

    MSBuild "MyProjectName.csproj" /T:Package /P:Configuration=Staging
    MSBuild "MyProjectName.vbproj" /T:Package /P:Configuration=Staging

    The setting /P:Configuration specifies the MSDeploy Property named Configuration, which in this example is set to Staging.

Specifying a Web Package Location

One common value that you might want to override from the command line is the location where the completed Web package is stored. You can specify the location using the PackageLocation property. In the following example, the PackageLocation property is set with the Configuration property. To specify more than one property, you separate multiple properties using a semicolon as shown for the Configuration and PackageLocation properties.

To specify a destination for the Web package using MSBuild

  1. Open the Visual Studio Command Prompt.

  2. Type the following at the command prompt:

    MSBuild "MyProjectName.vbproj" /T:Package /P:Configuration=Staging;PackageLocation="D:\mypackages\"
    MSBuild "MyProjectName.csproj" /T:Package /P:Configuration=Staging;PackageLocation="D:\mypackages\"

    When the command is run, a Web package using the Staging configuration is created in D:\mypackages\

    It is a good practice to name a Web package with the name of the project and a version number.

See Also


ASP.NET Web Application Projects Deployment Overview

Other Resources