How to deploy ASP.NET Core 1.0.1 to Heroku ?
💻 coding

How to deploy ASP.NET Core 1.0.1 to Heroku ?

1 min read 258 words
1 min read
ShareWhatsAppPost on X
  • 1Heroku does not support ASP.NET out-of-the-box, but ASP.NET Core can run on Linux, enabling deployment on Heroku.
  • 2To deploy, create a Heroku app using the ASP.NET Core buildpack and push your project to Heroku master.
  • 3Ensure the Microsoft.NETCore.App version is set to '1.0.1' and configure the Program.Main() method to use the PORT environment variable.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"Heroku does not support ASP.NET out-of-the-box, but ASP.NET Core can run on Linux, enabling deployment on Heroku."

How to deploy ASP.NET Core 1.0.1 to Heroku ?

Heroku is a great Infrastructure as a Service platform that provides easy deployment for Node, Ruby, PHP, Go, and many others – unfortunately, this does not include ASP.NET out-of-the-box. This is because ASP.NET has been a Windows-only platform since its inception, and Heroku only supports Linux. BUT, ASP.NET Core is out (Hurray) and we can now run our .NET apps on Linux! Still, no direct Heroku support, but here’s how to get up-and-running.

1. Create the Heroku app using an ASP.NET Core buildpack.

This ASP.NET Core Buildpack worked great for me. Just follow its steps in the Usage section:

$ heroku create --buildpack https://github.com/sumitc91/dotnetcore-buildpack
$ git push heroku master

2. Create your project in the root of the Git repo or set the config to point at the correct project.

If you don’t want to use the root of the repo, follow these steps to use a .deployment file to point at the appropriate folder.

3. Set Microsoft.NETCore.App version in project.json to “1.0.1”

(setting version 2.0.0 will not work with this buildpack)

4. Set up the Program.Main() method to use the PORT environment variable.

Heroku requires that whatever application you use is connected to a port specified by Heroku in the environment variables. This can be configured in the Program.cs file by changing the Main method to the following:

public static void Main(string[] args)
{
 var url = $"http://*:{Environment.GetEnvironmentVariable("PORT")}/";

 Console.WriteLine($"Using Url: {url}");

 var host = new WebHostBuilder()
 .UseKestrel()
 .UseContentRoot(Directory.GetCurrentDirectory())
 .UseIISIntegration()
 .UseStartup<Startup>()
 .UseUrls(url)
 .Build();

 host.Run();
}

5. Push to Heroku master

That’s it! You should be up and running.

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

AskGif

Published on 21 March 2019 · 1 min read · 258 words

Part of AskGif Blog · coding

You might also like