Blogs Hub

by AskGif | Mar 21, 2019 | Category :coding

How to deploy ASP.NET Core 1.0.1 to Heroku ?

How to deploy ASP.NET Core 1.0.1 to Heroku ?

<p>Heroku is a great Infrastructure as a Service platform that provides easy deployment for Node, Ruby, PHP, Go, and many others &ndash; 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&rsquo;s how to get up-and-running.</p> <p>&nbsp;</p> <p>1. Create the Heroku app using an ASP.NET Core buildpack.</p> <p>This ASP.NET Core Buildpack worked great for me. Just follow its steps in the Usage section:</p> <pre class="language-markup"><code>$ heroku create --buildpack https://github.com/sumitc91/dotnetcore-buildpack $ git push heroku master</code></pre> <p>2. Create your project in the root of the Git repo or set the config to point at the correct project.</p> <p>If you don&rsquo;t want to use the root of the repo, follow these steps to use a .deployment file to point at the appropriate folder.</p> <p>&nbsp;</p> <p>3. Set Microsoft.NETCore.App version in project.json to &ldquo;1.0.1&rdquo;</p> <p>(setting version 2.0.0 will not work with this buildpack)</p> <p>&nbsp;</p> <p>4. Set up the Program.Main() method to use the PORT environment variable.</p> <p>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:</p> <pre class="language-markup"><code>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&lt;Startup&gt;() .UseUrls(url) .Build(); host.Run(); }</code></pre> <p>5. Push to Heroku master</p> <p>That&rsquo;s it! You should be up and running.</p>

read more...