Let's create an ASP.NET Core application that we can deploy in Microsoft Azure:
The ASP.NET Core application will be created once you click the OK button:
As the default ASP.NET Core Web Application template uses the Entity Framework, we need to execute the following command in order to create the database migration:
dotnet ef database update
Once you enter the command in Command Prompt (in the project's path), the migration file will be created. This migration file will contain all the changes to the database. This migration will be applied at the time of deployment at Azure so that Azure can create the necessary database scripts for Azure deployment:
Once the database migration is completed, right-click on the created Core application and select the Publish option, as shown in the following screenshot:
When you click the Publish option, you'll be shown the following screen, depicting various publishing options available for you:
Please select the Microsoft Azure App Service option to publish the web application on the Microsoft Azure platform:
Click on the New button, and you will get the following screen:
You can change the web app name to whatever name you would like to have. I have changed the web app name to learningmvc6.
Click on the New button beside the Resource Group and enter the name for the resource group. The resource group is just a tag where you can group all of your computing resources so that if you want to delete all the resources, you can just delete the resource group. For example, a resource group could comprise of a web server and a database server—you can think of it like a collection of resources.
Now, click on the New button beside the App Service Plan. You will get the following window where you can choose the location and size of your web application container. Your location could be anywhere from South Central US to Europe, from Japan to Canada. Your application container could be anything from free to a machine with 7 GB RAM. I have chosen the free option as our objective is to deploy the ASP.NET Core application in a cloud environment rather than to deploy an application which is to be accessed by millions of users. Of course, you can achieve the same with ASP.NET Core and Microsoft Azure:
Now, we can configure the SQL database which is available as an additional Azure service.
Click on the + button which is available at the top section which will lead us to the configuration of the SQL database.
If you have any existing SQL server in the Azure environment, you can use it. As I don't have any such server, I am going to create a SQL server by clicking the New button beside SQL Server:
Please enter the administrator user name and password for the SQL Server and click OK. You will see the following screen:
Once you click OK, you will get the following screen:
Click OK on the preceding screen and we will see the Create App Service screen:
Click Create once we have configured all the required Azure services:
The preceding screen shows the deployment configuration options, such as the Site name and Destination URL for our application. Click Next on the preceding screen:
It is important to note that you need to expand the Databases option and Entity Framework Migrations options and select both the checkboxes. The first checkbox represents the connection string that should be used at runtime and the second checkbox represents the database migration that should be applied on publication.
The preceding screen is the preview screen where you can see the files that would be deployed when you publish. This is an optional step—if you want to see the files, you can click the Start Preview button. Or else, you can click the Publish button to publish the web application in the Azure platform.
Once you click the Publish button, our ASP.NET Core application will be deployed in Azure and your application URL will be opened on successful publication. You will get the following screen: