Want to know how you can get started quickly with ASP.NET Core 1.0 and run it on Azure Web Apps?

Then this is the post for you :)

I'll be doing a small series on ASP.NET Core and .NET Core now that 1.0 is out.

Possible topics I have in mind:

Required tools

  1. Visual Studio 2015: You can download the Community Edition here
  2. VS 2015 Update 3: If you did not get it from the previous step (or already had VS2015), download it from here
  3. .NET Core tools for VS2015: Download from here

Creating the project

To create the project, open Visual Studio 2015.

In the New Project dialog select Templates -> Visual C# -> Web -> ASP.NET Core Web Application (.NET Core). Give the project a name and choose its location. Click Create.

In the creation dialog, you can choose which basic template you want:

Project template chooser

  1. Empty: Literally empty project. Choose if you want to start from scratch.
  2. Web API: Choose if you want to create an API.
  3. Web Application: Choose if you want to create a user-facing web application.
    • Note that you can mix API and user-facing application also, they are both in the same framework.
    • In this example, I will use this template with individual user accounts

Note that you can also choose what kind of authentication you want with the Web API and Web Application options.

Running locally

After the library restore is done, you can start the app through Debug -> Start Debugging.

App running

I clicked the button that says Register to create a test user account. Now after I clicked the button I thought "Wait so what about DB migrations?". And I was greeted with this:

Error for not running migrations

"Is that a button for running the migrations???" Yes it is. Whoever made this error page, you deserve a medal. After clicking that and refreshing the page, everything was working as expected.

Publishing to Azure

First I created the Web App + Azure SQL Database in Azure Portal. This is quite easy to do with the Web App + Azure SQL Database template.

Creating app and DB

Go back to VS2015, and stop debugging and right-click on the project. Find the option Publish....

Select Microsoft Azure App Service as target. Log in with your Azure credentials, select the existing app you want to publish to, or create a new one.

Now you can go through the Publish dialog as usual, but on the last page we have some options:

Database publish settings

I chose to change the connection string here because I have not tested how loading the connection strings at runtime from App Service works yet.

I also chose to run migrations on publish so the database schema is updated in Azure SQL.

And tadah! The app is running in Azure and using Azure SQL for data storage :)

Check the official documentation for more information.