How to: Migrate and publish a web application to an Azure Cloud Service from Visual Studio
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
To take advantage of the hosting services and scaling ability of Azure, you might want to migrate and deploy your web application to an Azure cloud service. Only minimal changes are required. This article covers deploying to cloud services only; for App Service, see Deploy a web app in Azure App Service.
This migration is supported only for the specific ASP.NET, WCF, and WCF Workflow projects. It is not supported for ASP.NET Core projects. See Supported Project Templates.
Migrate a project to cloud services
Right-click the solution node and select Add > New Project... and add a new Azure Cloud Service (classic) project to the existing solution.
In the New Microsoft Azure Cloud Service (classic) dialog, click OK without adding any roles to the project.
Right-click the roles node under the newly added Cloud Services project and select Add Web Role Project in solution....
In the Associate with Role Project dialog, select the project you would like to associate as a web role.
If you have other assemblies or files that are required for this web application, you must manually set the properties for these files. For information about how to set these properties, see Include Files in the Service Package.
Errors and warnings
Any warnings or errors that occur indicate issues to fix before deploying to Azure, such as missing assemblies.
If you build your application, run it locally using the compute emulator, or publish it to Azure, you might see the error: "The specified path, file name, or both are too long." This error indicates that length of the fully qualified Azure project name exceeds 146 characters. To correct the issue, move your solution to a different folder with a shorter path.
For more information about how to treat any warnings as errors, see Configure an Azure Cloud Service Project with Visual Studio.
Test the migration locally
- In Visual Studio Solution Explorer, right-click the added cloud service project and select Set as Startup Project.
- Select Debug > Start Debugging (F5) to launch the Azure debugging environment. This environment specifically provides emulation of various Azure services.
Use an Azure SQL Database for your application
If you have a connection string for your web application that uses an on-premises SQL Server database, you must migrate your database to Azure SQL Database instead and update your connection string. For guidance with this process, refer to the following topics:
- SQL Server database migration to SQL Database in the cloud
- Use .NET (C#) with Visual Studio to connect and query and Azure SQL database.
Publish the application to Azure Cloud Service
Create the necessary cloud service and storage accounts in your Azure subscription as described on Prepare to publish or deploy an Azure application from Visual Studio.
In Visual Studio, right-click the application project and select Publish to Microsoft Azure... (which is different from the "Publish..." command.).
In the Publish Azure Application that appears, sign in using the account with your Azure subscription and select Next >.
In the Settings > Common Settings tab, select the target cloud service from the Cloud Service drop-down list, along with your chosen environment and configurations.
In Settings > Advanced Settings, select the storage account to use, then select Next >.
In Diagnostics, choose whether to send information to Application Insights.
Select Next > to view a summary, then select Publish to start deployment.
Visual Studio opens an activity log window where you can track progress:
(Optional) To cancel the deployment process, right-click the line item in the activity log and choose Cancel and remove. This command stops the deployment process and deletes the deployment environment from Azure. Note: to remove this deployment environment after it has been deployed, you must use the Azure portal.
(Optional) After your role instances have started, Visual Studio automatically shows the deployment environment in the Server Explorer > Cloud Services node. From here you can view the status of the individual role instances.
To access your application after deployment, choose the arrow next to your deployment when a status of Completed appears in the Azure Activity log along with the URL. See the following table for the details about how to start a specific type of web application from Azure.
Using the compute emulator and starting application in Azure
All application types can be started in a browser connected to the Visual Studio debugger by selecting Debug > Start Debugging (F5). With an ASP.NET Empty Web Application project, you must first add an
.aspx page in your application and set it as the start page for your web project.
The following table provides details about starting the application in Azure:
|Web Application Type||Running in Azure|
|ASP.NET Web Application
(including MVC 2, MVC 3, MVC 4)
|Select the URL in the Deployment tab for the Azure Activity log.|
|ASP.NET Empty Web Application||If you have a default
|WCF Service Application
WCF Workflow Service Application
|ASP.NET Dynamic Entities
ASP.NET Dynamic Data Linq to SQL
|Update the connection string as described in the next section. Then navigate to
Update a Connection String for ASP.NET Dynamic Entities
Create a SQL Azure database for a ASP.NET Dynamic Entities web application as described earlier in (#use-an-azuresql-database-for-your-application).
Add the tables and fields that you need for this database from the Azure portal.
Specify a connection string in the
web.configfile with the following format and save the file:
<add name="tempdbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=<server name>\SQLEXPRESS;initial catalog=<database name>;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>
Update the connectionString value with the ADO.NET connection string for your SQL Azure database as follows:
<add name="tempdbEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:<SQL Azure server name>.database.windows.net,1433;Database=<database name>;User ID=<user name>;Password=<password>;Trusted_Connection=False;Encrypt=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>
Supported Project Templates
Applications that can be migrated and published to cloud services must use one of the templates in the table below. ASP.NET Core is not supported.
|Template Group||Project Template|
|Web||ASP.NET Web Application (.NET Framework)|
|Web||ASP.NET MVC 2 Web Application|
|Web||ASP.NET MVC 3 Web Application|
|Web||ASP.NET MVC4 Web Application|
|Web||ASP.NET Empty Web Application (or Site)|
|Web||ASP.NET MVC 2 Empty Web Application|
|Web||ASP.NET Dynamic Data Entities Web Application|
|Web||ASP.NET Dynamic Data Linq to SQL Web Application|
|WCF||WCF Service Application|
|WCF||WCF Workflow Service Application|
|Workflow||WCF Workflow Service Application|
Submit and view feedback for