Publishing an ASP.NET 5 (vNext) Application

Ray HuangNote that some of the information presented here regarding .NET 5 is no longer valid, due to fundamental changes made on the way to .NET 5 becoming ASP.NET Core 1.0. You can read more about those changes in the article, “Revisiting ASP.NET Core 1.0.”

For those tech gurus who just love to work with the latest Microsoft programming technologies, here’s a simple tutorial on how you can publish an ASP.NET 5 (vNext) application to DiscountASP.NET.

Please note that ASP.NET 5 (vNext) is still in Beta, so the instructions given today may or may not be valid in the future. The Release Candidate will not be available until November with the final release being slated for some time in the first quarter of 2016. More information can be found at Microsoft’s Roadmap. You’ll also want to go to the Official Website to read up on the new features as the file structure is very different from traditional web forms and MVC programming.

Another key feature is that vNext has been designed for maximum portability, allowing you to deploy your code to a Mac or Linux operating system. This guide is meant for developers who want to try it out now and only covers the publishing aspect, using the sample ASP.NET 5 Preview Template as an example.

Publishing the application locally and then uploading it using FTP:

In order to create a vNext application, you’ll need to obtain a copy of Visual Studio 2015 Professional or higher. Install it and then launch the program.

1) Select File -> New -> Project…

FileNewProject

2) Under Visual C#, select Web and to the right, select ASP.NET Web Application. I’ll give this project a name vNextDemo.

NewProjectWindow

3) Now in the New ASP.NET Project window, select Web Application for the ASP.NET 5 Preview Template. You can also uncheck Host in the cloud under Microsoft Azure. Click the OK button to continue.

ASPNET5PreviewTemplate

4) Notice the new file structure in the Solution Explorer window. All the configuration files are now stored as JSON (JavaScript Object Notation) format. I won’t go into details regarding any programming aspects as this is not the purpose of this guide but wanted to point out a few things that you should be aware of. References are now added to your project using NuGet, and an ASP.NET vNext application publishes two folders, an approot folder containing all your assemblies, runtime libraries, and source code and a wwwroot folder which contains the static content of your website (e.g. html, images, css, etc.). This is important to know as it must be maintained in order for your application to work properly.

SolutionExplorer

5) Since the sample application is already complete, let’s start the publishing process. Select Build -> Publish from the menu bar.

BuildPublish

6) Click on File System.

FileSystem

7) Give the profile a name.

ProfileName

8) Find a path on your local machine to target the publishing. I created a vNextDemo folder under the Downloads folder. Click the Next> button.

TargetDirectory

9) On the Settings page, choose Release for Configuration. For the Target DNX Version, you should be able to choose any, but it should match the framework your application is written in. For more information about DNX and what it is, the official documentation can be found here.  If you plan to use the 64-bit versions, you will need to open up a support ticket to request that support for 32-bit applications to be disabled in order for it to work properly.  You can uncheck Publish using Powershell script. Click on Next>.

Settings

10) Click the Publish button to start.

Publish

11) After your project has been published, you should see the two folders approot and wwwroot.

PublishedFiles

12) Open up the web.config file in the wwwroot folder and add the following XML markup in the <configuration> section to enable Full trust:

<system.web>
    <trust level="Full" />
</system.web>

Upload these two folders to your hosting account. You can ignore the other files. Now, mark the wwwroot folder as a Web Application using the tool in the DiscountASP.NET Control Panel.

WebApplicationTool

13) That’s it. Your application now works but only from a sub-directory (i.e. http://www.mysite.com/wwwroot).

wwwrootDeployed

Publishing the application to the root of the site:

If you want it to work in the root, you just need to make a few modifications after publishing. First, modify the project.json file in /approot/src/projectname directory by changing the first line from “webroot”: “../../../wwwroot” to “webroot”: “../../../htdocs”.  Upload the contents of the wwwroot folder directly to the root of the hosting account along with the approot folder. Open a support ticket and request that we move the approot folder one level up (i.e. on the same level as the htdocs folder). And voila, your application is now working from the root.

nowwwrootDeployed

Publishing Directly Using FTP within Visual Studio:

You can also publish directly using FTP within Visual Studio by creating and using a publishing profile. Open up Notepad, copy and paste the following markup (contents) into Notepad:

<?xml version="1.0" encoding="utf-8"?>
<publishData>
  <publishProfile profileName="FTP" publishMethod="FTP" publishUrl="ftp://ftpaddress" userName="username" userPWD="password" destinationAppUrl="http://wwwaddress" />
</publishData>

replacing ftpaddress, username, password, and wwwaddress with the appropriate values. Save the file and name it ftp.publishhsettings without the .txt extension. Now at Step 6 above, instead of choosing File System, select Import instead and use the ftp.publishsettings file. The rest of the instructions that follow should apply when configuring the application.

Please note that Web Deploy publishing is not supported at this time and to run an ASP.NET 5 (vNext) application requires it to be deployed to an IIS 7.5 or higher server.

2 thoughts on “Publishing an ASP.NET 5 (vNext) Application

  1. Thanks for this. I’ve just deployed an MVC6 app using this guide but am getting an error with the web.config. Locally, I get an error “The element ‘system.webServer’ has invalid child element ‘httpPlatform” but I can still run the app. However, live is a different story. I wonder is there anything I need to do?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.