Edit

Building Azure projects from the command line

Note

This article applies to Azure Azure Cloud Services (extended support). On March 31, 2027, the Cloud Services (Extended Support) deployment model will be retired. As a result, the supporting Cloud Services tooling will not be available in the latest Visual Studio after this date. Cloud Services (Extended Support) tooling will continue to work in Visual Studio 2022 with general maintenance occurring until March 31, 2027. We recommend starting your migration planning now to ensure a smooth transition. See the official announcement for more information, including detailed guidance on migrating your apps to modern Azure services.

Azure Cloud Services relies on connection strings for authentication in some cases, such as for storage accounts. Connection strings and passwords are inherently insecure due to the risk of unintended exposure or compromise. Microsoft recommends using managed identities for authentication, and services such as Service Fabric managed clusters.

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.