How to Push an ASP.NET 5 Application to IBM Bluemix

by Eugene LahanskyMarch 25, 2016
Last year, IBM introduced several new services in Bluemix, including the .NET Runtime and open-source ASP.NET 5 buildpack.

ibm-bluemix-asp.net-5-asp.net-core-1.0-v1

With the announcement from IBM, Cloud Foundry-based environments became available for ASP.NET 5 applications. In this tutorial, we show how to deploy a simple ASP.NET application to Bluemix.

 

Prerequisites

Bluemix only supports ASP.NET 5, which Microsoft is currently renaming to ASP.NET Core 1.0, so the previous versions might not work in Bluemix.

To follow the steps of this tutorial, you need:

 

Creating an application in the Bluemix console

To create an application:

  1. Log in to your Bluemix account and navigate to Dashboard.
  2. Click Create App, choose Web, and then select the ASP.NET 5 runtime from the list.
  3. Name your application.

That’s it, you are done with the Bluemix console.

 

Preparing an application for Bluemix

In the Bluemix console, you can see the generated endpoint URL for your application similar to http://<your app name>.eu-gb.mybluemix.net.

  1. Go to Microsoft Visual Studio 2015 and create a new project using a standard ASP.NET 5 template.
  2. Compile and start the application to check if it works locally.
  3. ibm-bluemix-microsoft-visual-studio-v1

  4. For deploying the application in Bluemix, modify the project.json file.

    First, include the Microsoft.AspNet.Server.Kestrel dependency and the kestrel command. Then, make sure your application targets the dnxcode50 framework.

    These changes help Bluemix to choose the correct buildpack for the application. Here is how the project.json file should look like:

    "dependencies": {
    ...
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
    },
    "commands": {
    ...
        "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel"
    },
    "frameworks": {
        "dnxcore50": { }
    }
    ...
  5. Compile and start the application again to check if the configuration is valid.

 

Pushing the application to Bluemix

After we prepared the application for Bluemix, it’s time to deploy it with Cloud Foundry.

ibm-bluemix-application-overview-v1

First, open the Bluemix console, navigate to Dashboard, and click the recently created application. On the Overview page, select the Start Coding section from the left menu. This page has all the instructions needed to deploy the application. In particular, Bluemix offers two ways:

  • using the Cloud Foundry Command Line Interface
  • using Git

I am going to use the command line interface. If you prefer working with Git, follow the instructions from this video tutorial.

With the IBM Bluemix and Cloud Foundry command line interfaces installed, go through these steps:

  1. Open cmd.exe and change to your ASP.NET directory:

    cd <folder where project.json is located>
  2. Set Bluemix api for your further API calls:

    bluemix api https://api.eu-gb.bluemix.net
  3. Log in to your account:

    bluemix login -u <your bluemix email> -o <your bluemix organization> -s dev

    where:

    • -u sets the username.
    • -o sets the organization.
    • -s sets the environment.

    You will be also asked for your password—the one you chose during the registration.

  4. After logging in, push the application:

    cf push eugenetestaspnet5 -b https://github.com/cloudfoundry-community/asp.net5-buildpack.git

    The cf push command has two parameters:

    • the Bluemix application name (required)
    • the Cloud Foundry buildpack (optional). If you skip the -b parameter, Bluemix automatically decides which buildpack to use based on your project.json file.

You can see the result in the browser: http://<your app name>.eu-gb.mybluemix.net/.

pushing-asp.net-5-app-to-ibm-bluemix-v1

 

Conclusion

It took me about two minutes to create the droplet for the first time and upload it to the Bluemix server. This process, however, can take a bit more or less time depending on your Internet connection. In addition, cf push has some caching functionality to decrease the command execution time. In my future posts, I am going to show how to work with different Bluemix services from our sample ASP.NET application.

 

Related reading