This post is about how you can bring your ASP.NET 5 website (or build a new one using the asp.net Yeoman generator) up into the Heroku cloud. It’s super quick, smooth and easy experience to deploy it using a third-party build pack.
Tag along though this post, and let me know in the comments what your thoughts are.
Note: If you haven’t read the previous post about Building a MEAN (MongoDB, ExpressJs, Angular and Node.js) API app using TypeScript and host it with Heroku, I would suggest you check it out.
Part 1: Setup the git repository
In order to work with Heroku CLI which I’ll be doing, you’ll need a git repository as the base for your asp.net project.
Either git init a new repository or git clone <repo url> an existing one.
In my case I’m cloning an empty repo from my GitHub, and then I’ll create the ASP.NET 5 app there, which I’ll later publish to Heroku. The final code for that web app can be downloaded below.
Download: To get the full source code for my ASP.NET 5 sample project, check it out on GitHub.
Part 2: Create the ASP.NET 5 Website
I assume you’ve got a repository to work with at this point. For the sake of clarity, my repository is empty at this point and I’ll create the contents of it as we go.
If you’ve got an ASP.NET 5 web site in your repo already, skip to Part 3.
Install the required tooling
If you haven’t done this already, you should install the required toolings to work with the Yeoman generator for ASP.NET core.
Install bower and yeoman (yo):
npm install -g yo bower
Install the aspnet generator for yeoman:
npm install -g generator-aspnet
Generate the base for our website with Yeoman
We’re using Yeoman.
If you’re new to yeoman, please read more on the Yeoman website
yo aspnet
As per the aforementioned steps, we’ve installed the required tooling. Namely yeoman, bower and our asp.net core generator.
Create your ASP.NET basic web application:
yo aspnet

- Select the
Web Application Basic [without Membership and Authorization] - Select
BootstraporSemantic. I went for Semantic! - Put a name to it. Mine is
AspnetWithHeroku - Watch the generator flow.
This process takes only a matter of seconds (possibly longer if your machine isn’t awesome), and should give you something similar to this:

Edit the generated project
I’m using Visual Studio Code to make some slight modifications, just to make sure this newly generated website is unique and we can distinguish it once we’ve published to Heroku.
I’m changing the header in the Index.cshtml file so the site simply looks like this:

Great. You have a working ASP.NET 5 website (an existing one, or a newly generated one like mine here).
Restore, build and run local website
Before we even start considering pushing these things into the cloug, we should verify that they work locally.
With ASP.NET 5 this is very easy, and done like this:
First, you run:
dotnet restore
This will install all the required packages and restore them into your project.
Once this is done, we can simply make sure that the web app launches.
Next, run this:
dotnet build
This will build the project and make sure you don’t have any build errors etc.
Next, run this:
dotnet run
Et voila! There should be a link telling you where to find your running localhost application:

Launching that url in your browser, you should see your web application. Mine looks like the preview I showed you under the previous headline.
Part 3: Deploying and running your ASP.NET 5 web application in Heroku!
This is where the fun part starts. If you’ve reached this point, it assumes that you’ve got an ASP.NET 5 core application you’d want to host in Heroku.
Make sure you’ve got your web app in a git repo, as described in the beginning.
Before we walk through the few steps required, let’s take a step back and talk slightly about Heroku and its options.
Heroku Buildpacks
Buildpacks are responsible for transforming deployed code into a slug, which can then be executed on a dyno. Buildpacks are composed of a set of scripts, and depending on the programming language, the scripts will retrieve dependencies, output generated assets or compiled code, and more. This output is assembled into a slug by the slug compiler - Heroku Dev Center
Essentially a way to tell Heroku how to run your code.
Official Buildpacks supported by Heroku
There’s a handful of officially supported buildpacks (as of this writing), and they are:
As you can see, the ASP.NET build packs isn’t there. That is sad. But, alas, this is where the Heroku Elements Marketplace comes to the rescue!
Unofficial Buildpacks in the Heroku Elements Marketplace

Visiting the Heroku Elements Marketplace, I started to look what they had to offer.
There’s a LOT of buildpacks available from thirdparty repos. Both good ones and bad ones, and this is why they might not be officially supported by Heroku.
It tested a few different ones, but not everyone worked - so this will be an important task for you if you choose to use something from the thirdparty offerings here. Do you research and tests, and make sure it keeps running for you!
Since our project is running ASP.NET 5 on .net core, we will search for a buildpack that might offer something like that:

I found the one in the picture, called dotnet-buildpack from this location: https://elements.heroku.com/buildpacks/noliar/dotnet-buildpack.
I tested it, created a heroku app based on it and voila. It worked. That’s what the next section is about.
Create and deploy a Heroku app based on ASP.NET 5
This part is the easy one. Once you’ve verified a build pack and you know what you’re going to do, just do it. Here’s how.
Create a Heroku app based on the dotnet core buildpack from noliar:
heroku create --buildpack http://github.com/noliar/dotnet-buildpack.git
It will look something like this:

Commit any changes in your repository:
git add *
git commit -m "Added all my magical unicorns"
Push the repository master branch to the heroku app:
git push heroku master
Note: If you get the
fatal: 'heroku' does not appear to be a git repositorymessage at this point, here’s how you resolve that:
heroku git:remote -a yourApplicationHere
The yourApplicationHere is the name of your application in Heroku, as you created previously

When you’ve pushed your master to Heroku, it will start to walk through all steps necessary to build and deploy your asp.net 5 web application in the Heroku dyno.
Once this is done, you should hopefully see a message indicating success:

Next up, simply run this to launch your newly published web app, now hosted in the Heroku dyno:
heroku open
That will launch your ASP.NET 5 app, now running in Heroku:

Get an overview of your deployed app
With Heroku, you can visit your admin portal to see the status of your application. You can do this through the CLI too, but let’s check the UI out.
This is all done through your dashboard on https://dashboard.heroku.com/apps.
In your app overview, you will notice that the type is now ASP.NET Core:

Clicking in to your app, you can see the deployment history and make sure it’s successful:

Summary
In this post we’ve checked out how to:
- Create a templated ASP.NET 5 website
- Created a Heroku app with a custom buildtemplate (for dotnet core)
- Hooked up our repository to the heroku app
- Deployed our repository code to the Heroku cloud
The source code for the simple ASP.NET 5 website is available here: https://github.com/Zimmergren/heroku-aspnet5
Enjoy.
Tobias.
Comments are closed
Archived comments
Hi,
Thank you for posting the details on deploying asp.net app to Heroku.
I am deploying an asp.net core 1.0.1 application but I am getting below message.
2016-11-03T19:17:14.845513+00:00 heroku[web.1]: Starting process with command `cd /app/heroku_output && dotnet ./tmp.ZSye99IiKN.dll --server.urls http://+:58751`
2016-11-03T19:17:17.123357+00:00 app[web.1]: The specified framework 'Microsoft.NETCore.App', version '1.0.1' was not found.
2016-11-03T19:17:17.123379+00:00 app[web.1]: - Check application dependencies and target a framework version installed at:
2016-11-03T19:17:17.123380+00:00 app[web.1]: /app/dotnet/shared/Microsoft.NETCore.App
2016-11-03T19:17:17.123383+00:00 app[web.1]: - The following versions are installed:
2016-11-03T19:17:17.123386+00:00 app[web.1]: 1.1.0
2016-11-03T19:17:17.192858+00:00 heroku[web.1]: Process exited with status 131
2016-11-03T19:17:17.123389+00:00 app[web.1]: - Alternatively, install the framework version '1.0.1'.
2016-11-03T19:17:17.207452+00:00 heroku[web.1]: State changed from starting to crashed
It says 1.1.0 is installed but my app is 1.0.1. I tried to change the version in my app to 1.1.0 but it is failing to restore the version as we have 1.1.0 preview version
Could you please let me know how to fix this issue.
Thank you in advance
Hey Hermant,
When I built this project it was targeting 1.0.1 which was the same as the version deployed in Heroku. I would suggest checking out the buildpacks you're using, and see which version is used there and make sure you match that - or see if there's a way to upgrade the Heroku app to the same version as your project. It's only a matter of version mismatching and should be resolved if you manage to match the versions :-)
Tobias.
I am getting the following error:
https://uploads.disquscdn.c...
Any ideas?
Thanks
Hey Carlo,
Did you install the third-party buildpack as I did in my post? ( heroku create --buildpack http://github.com/noliar/do...
) based on the on here: https://elements.heroku.com...
Tobias.
I have the same error.. I did all the steps
there is an error with one of your files, a semi colon, etc, try to check files again
Hi Tuxracer,
Please see my response below to Hermant: https://zimmergren.net/buil...
Make sure the version you're building is matching the version of .net core you're trying to publish to. It's a version mismatch between 1.0.1 and 1.1.0 :)
I am getting the following error can you help me? Thanks
https://uploads.disquscdn.c...
Thank you a million Mr Tobias,
And If I may humbly request this tutorial is a very nice educative and intuitive one but it would be more easier to understand the steps if it were also made in a kind of YouTube video tutorial. Thanks in advance.
Hey, @disqus_EkLvhk1tkQ:disqus
Unfortunately, it's been five years since I published this post, and a lot of things has changed. I'm not using Heroku now, but I'm sure there's plenty of other sources, including videos, of how to achieve something similar.
I would perhaps make sure to use .NET 6 LTS, and find any references on the public Heroku site.
Thanks for your kind words and comment, and I hope you find a way to solve your challenges :)
Tobias.
Thanks alot, yes I did, used Azure n I will look up .NET 6 LTS.