Building Azure projects from the command line

Note

This article applies to Azure Azure Cloud Services (extended support). Cloud Services (classic) is retired as of August 31, 2024. For more information, see Cloud services (classic) deployment model is retiring on August 31, 2024. For new development, we recommend that you use a newer service type designed for your specific purpose, such as Azure App Service, Azure Functions, or Azure Container Apps. For the latest list of available services, see Directory of Azure products.

Using the Microsoft Build Engine (MSBuild), you can build products in build-lab environments where Visual Studio is not installed. MSBuild uses an XML format for project files that's extensible and fully supported by Microsoft. Using the MSBuild file format, you can describe what items must be built for one or more platforms and configurations.

You can also run MSBuild at the command line, and this topic describes that approach. By setting properties on the command line, you can build specific configurations of a project. Similarly, you can also define the targets that MSBuild builds. For more information about command-line parameters and MSBuild, see MSBuild Command-Line Reference.

MSBuild parameters

The simplest way to create a package is to run MSBuild with the /t:Publish option. By default, this command creates a directory in relation to the root folder for the project, such as <ProjectDirectory>\bin\Configuration\app.publish\. When you build an Azure project, two files are generated: the package file itself and the accompanying configuration file:

  • Package File (project.cspkg)
  • Configuration File (ServiceConfiguration.TargetProfile.cscfg)

By default, each Azure project includes one service-configuration file for local (debugging) builds and another for cloud (staging or production) builds. However, you can add or remove service-configuration files as needed. When you build a package within Visual Studio, you are asked which service-configuration file to include alongside the package. When you build a package by using MSBuild, the local service-configuration file is included by default. To include a different service-configuration file, set the TargetProfile property of the MSBuild command (MSBuild /t:Publish /p:TargetProfile=ProfileName).

If you want to use an alternate directory for the stored package and configuration files, set the path by using the /p:PublishDir=Directory\ option, including the trailing backslash separator.

After the package is built, you can deploy it to Azure.