2016-10-29 01:35:15 +08:00
---
2017-07-01 07:47:15 +08:00
title: Publish an ASP.NET Core app to Azure using Visual Studio
2016-10-29 01:35:15 +08:00
author: rick-anderson
2018-01-10 09:41:28 +08:00
description: Learn how to publish an ASP.NET Core app to Azure App Service using Visual Studio.
2016-10-29 01:35:15 +08:00
manager: wpickett
2018-01-29 23:21:31 +08:00
ms.author: riande
2017-12-19 09:57:26 +08:00
ms.date: 12/16/2017
2017-03-03 08:50:36 +08:00
ms.prod: asp.net-core
2018-01-29 23:21:31 +08:00
ms.technology: aspnet
ms.topic: get-started-article
2016-10-29 01:35:15 +08:00
uid: tutorials/publish-to-azure-webapp-using-vs
---
2017-04-08 04:11:19 +08:00
# Publish an ASP.NET Core web app to Azure App Service using Visual Studio
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
By [Rick Anderson ](https://twitter.com/RickAndMSFT ), [Cesar Blum Silveira ](https://github.com/cesarbs ), and [Rachel Appel ](https://twitter.com/rachelappel )
2016-10-29 01:35:15 +08:00
2018-02-28 13:18:58 +08:00
[!INCLUDE[Azure App Service Preview Notice ](../includes/azure-apps-preview-notice.md )]
2018-03-16 03:48:55 +08:00
See [Publish to Azure from Visual Studio for Mac ](https://blog.xamarin.com/publish-azure-visual-studio-mac/ ) if you are working on macOS.
2017-11-09 04:28:26 +08:00
2017-10-06 07:13:39 +08:00
## Set up
2016-10-29 01:35:15 +08:00
2018-01-24 23:27:24 +08:00
* Open a [free Azure account ](https://aka.ms/K5y5yh ) if you don't have one.
2016-10-29 01:35:15 +08:00
## Create a web app
2017-09-11 22:53:42 +08:00
In the Visual Studio Start Page, select **File > New > Project...**
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![File menu ](publish-to-azure-webapp-using-vs/_static/file_new_project.png )
2016-10-29 01:35:15 +08:00
Complete the **New Project** dialog:
2017-09-11 22:53:42 +08:00
* In the left pane, select ** .NET Core**.
* In the center pane, select **ASP.NET Core Web Application** .
* Select **OK** .
2016-10-29 01:35:15 +08:00
2016-12-23 02:03:29 +08:00
![New Project dialog ](publish-to-azure-webapp-using-vs/_static/new_prj.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
In the **New ASP.NET Core Web Application** dialog:
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select **Web Application** .
* Select **Change Authentication** .
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![New Project dialog ](publish-to-azure-webapp-using-vs/_static/new_prj_2.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
The **Change Authentication** dialog appears.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select **Individual User Accounts** .
* Select **OK** to return to the **New ASP.NET Core Web Application** , then select **OK** again.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![New ASP.NET Core Web authentication dialog ](publish-to-azure-webapp-using-vs/_static/new_prj_auth.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
Visual Studio creates the solution.
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
## Run the app
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
* Press CTRL+F5 to run the project.
* Test the **About** and **Contact** links.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![Web application open in Microsoft Edge on localhost ](publish-to-azure-webapp-using-vs/_static/show.png )
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
### Register a user
2017-09-11 22:53:42 +08:00
* Select **Register** and register a new user. You can use a fictitious email address. When you submit, the page displays the following error:
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
*"Internal Server Error: A database operation failed while processing the request. SQL exception: Cannot open the database. Applying existing migrations for Application DB context may resolve this issue."*
* Select **Apply Migrations** and, once the page updates, refresh the page.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![Internal Server Error: A database operation failed while processing the request. SQL exception: Cannot open the database. Applying existing migrations for Application DB context may resolve this issue. ](publish-to-azure-webapp-using-vs/_static/mig.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
The app displays the email used to register the new user and a **Log out** link.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![Web application open in Microsoft Edge. The Register link is replaced by the text Hello email@domain.com! ](publish-to-azure-webapp-using-vs/_static/hello.png )
2016-10-29 01:35:15 +08:00
## Deploy the app to Azure
Right-click on the project in Solution Explorer and select **Publish...** .
2016-12-23 02:03:29 +08:00
![Contextual menu open with Publish link highlighted ](publish-to-azure-webapp-using-vs/_static/pub.png )
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
In the **Publish** dialog:
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
* Select **Microsoft Azure App Service** .
* Select the gear icon and then select **Create Profile** .
* Select **Create Profile** .
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
![Publish dialog ](publish-to-azure-webapp-using-vs/_static/maas1.png )
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
### Create Azure resources
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
The **Create App Service** dialog appears:
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
* Enter your subscription.
* The **App Name** , **Resource Group** , and **App Service Plan** entry fields are populated. You can keep these names or change them.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![App Service dialog ](publish-to-azure-webapp-using-vs/_static/newrg1.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select the **Services** tab to create a new database.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select the green ** +** icon to create a new SQL Database
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![New SQL Database ](publish-to-azure-webapp-using-vs/_static/sql.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select **New...** on the **Configure SQL Database** dialog to create a new database.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![New SQL Database and server ](publish-to-azure-webapp-using-vs/_static/conf.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
The **Configure SQL Server** dialog appears.
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
* Enter an administrator user name and password, and then select **OK** . You can keep the default **Server Name** .
2016-10-29 01:35:15 +08:00
> [!NOTE]
2018-01-24 23:27:24 +08:00
> "admin" isn't allowed as the administrator user name.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![Configure SQL Server dialog ](publish-to-azure-webapp-using-vs/_static/conf_servername.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select **OK** .
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
Visual Studio returns to the **Create App Service** dialog.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select **Create** on the **Create App Service** dialog.
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![Configure SQL Database dialog ](publish-to-azure-webapp-using-vs/_static/conf_final.png )
2017-12-19 09:57:26 +08:00
Visual Studio creates the Web app and SQL Server on Azure. This step can take a few minutes. For information on the resources created, see [Additonal resources ](#additonal-resources ).
2016-10-29 01:35:15 +08:00
2017-12-19 09:57:26 +08:00
When deployment completes, select **Settings** :
![Configure SQL Server dialog ](publish-to-azure-webapp-using-vs/_static/set.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
On the **Settings** page of the **Publish** dialog:
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Expand **Databases** and check **Use this connection string at runtime** .
* Expand **Entity Framework Migrations** and check **Apply this migration on publish** .
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Select **Save** . Visual Studio returns to the **Publish** dialog.
2016-10-29 01:35:15 +08:00
2016-12-23 02:03:29 +08:00
![Publish dialog: Settings panel ](publish-to-azure-webapp-using-vs/_static/pubs.png )
2016-10-29 01:35:15 +08:00
2018-03-01 23:37:47 +08:00
Click **Publish** . Visual Studio publishs your app to Azure. When the deployment completes, the app is opened in a browser.
2016-10-29 01:35:15 +08:00
### Test your app in Azure
* Test the **About** and **Contact** links
* Register a new user
2017-09-11 22:53:42 +08:00
![Web application opened in Microsoft Edge on Azure App Service ](publish-to-azure-webapp-using-vs/_static/register.png )
2016-10-29 01:35:15 +08:00
### Update the app
2017-09-11 22:53:42 +08:00
* Edit the *Pages/About.cshtml* Razor page and change its contents. For example, you can modify the paragraph to say "Hello ASP.NET Core!":
[!code-html[About ](publish-to-azure-webapp-using-vs/sample/about.cshtml?highlight=9&range=1-9 )]
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Right-click on the project and select **Publish...** again.
2016-10-29 01:35:15 +08:00
2016-12-23 02:03:29 +08:00
![Contextual menu open with Publish link highlighted ](publish-to-azure-webapp-using-vs/_static/pub.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* After the app is published, verify the changes you made are available on Azure.
![Verify task is complete ](publish-to-azure-webapp-using-vs/_static/final.png )
2016-10-29 01:35:15 +08:00
### Clean up
When you have finished testing the app, go to the [Azure portal ](https://portal.azure.com/ ) and delete the app.
2017-09-11 22:53:42 +08:00
* Select **Resource groups** , then select the resource group you created.
2016-10-29 01:35:15 +08:00
2016-12-23 02:03:29 +08:00
![Azure Portal: Resource Groups in sidebar menu ](publish-to-azure-webapp-using-vs/_static/portalrg.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* In the **Resource groups** page, select **Delete** .
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
![Azure Portal: Resource Groups page ](publish-to-azure-webapp-using-vs/_static/rgd.png )
2016-10-29 01:35:15 +08:00
2017-09-11 22:53:42 +08:00
* Enter the name of the resource group and select **Delete** . Your app and all other resources created in this tutorial are now deleted from Azure.
2016-10-29 01:35:15 +08:00
### Next steps
2018-01-10 09:41:28 +08:00
* [Continuous Deployment to Azure with Visual Studio and Git ](xref:host-and-deploy/azure-apps/azure-continuous-deployment )
2017-12-19 09:57:26 +08:00
## Additonal resources
2018-01-24 09:12:57 +08:00
* [Azure App Service ](https://docs.microsoft.com/azure/app-service/app-service-web-overview )
* [Azure resource groups ](https://docs.microsoft.com/azure/azure-resource-manager/resource-group-overview#resource-groups )
* [Azure SQL Database ](https://docs.microsoft.com/azure/sql-database/ )