Nano Server is a slimmed down version of the coming Windows Server 2016 and in the last post, created a VHD image with Nano Server and startedit on Azure. This time I will deploy a website on the Nano Server using ASP.Net5, which is new in Visual Studio 2015. Since Nano Server only contains CoreCLR and not the entire .Net Framework, the website will also have to do with CoreCLR and this is one of the features of ASP.Net5.
DNX – .Net Execution Environment
New in ASP.Net5 is DNX, or .Net Execution Environment. With it you can install versions of clr and coreclr and you can even create, pack, publish and run web applications. In the references, I have a //build session by Scott Hanselman that you should watch.
First you need to make sure that you have the CoreCLR version that we are going to use. Using the commands DNVM LIST and DNVM INSTALL you can manage what runtimes you have locally. To get the webapp to run on the Nano Server, we must use coreclr with the x64 architecture, since that is the only supported options. The coreclr runtimes are stored in your user profile folder – in my case c:\users\cljung\.dnx.
In the next post, I will use Mono and put an ASP.Net5 website on a Ubuntu Linux server.
Build the webapp in Visual Studio 2015
Creating a webapp that uses coreclr is easy if you are using VS2015. Select the Empty ASP.NET 5 Template, like below.
From there on, right click on the project and select properties to set DNX target to the version of your CoreCLR with x64 architecture. Changing from .Net Framework to CoreCLR will give you yellow warning triangles on the References in VS2015 and to remove those you have to do Restore Packages. This could be done from the command line with the DNX command DNU RESTORE. The restore packages procedure basically pulls down all NuGet packages needed for the project under the current platform and architecture.
Last step is to Publish the application. Skip the Publish to Azure Website and set the profile for File System. Make sure that the DNX version is the correct (which it should be).
Publishing the website to Nano Server
The only option for deploying the website is file copy. There is no WebDeploy or similar. In fact, it is difficult just to unpack a zip file, since most Powershell scripts you’ll find on the internet uses the Windows Shell object – which doesn’t exist on the Nano Server. My deployment is done the simple way using Copy-Item from the local laptop, via the Powershell remote managament session, to the Nano Server on Azure. The $ip address in the script window is Azure’s public VIP for the VM. Copying is not fast and will take some time.
Before we start the website, the file hosting.ini needs to be edited. It contains the local ip adress that the website should bind to. Default is localhost, but that will not work on Azure. You need to change that to the internal ip address the Azure VM has, ie the ip address you see with ipconfig.This is a bit of a hazzle if you redeploy since you have to repeat the process.
You also need to add an Endpoint in Azure on the VM in the Azure Management Portal where you map public port 80 to private port 5000.
Starting the website
Starting the website is done via running a small file called web.cmd, which was created during the Publish procedure in VS2015. The web.cmd file contains one line where in uses the DNX command to run the website. It points to details in the project.json that gives DNX instructions what “run” actually means. On a Ubuntu Linux server, the project.json file will contain details on how to launch the website in that environment.
Website running on Nano Server
Below you see a screenshot of the ASP.Net5 website running on a Nano Server operating system in Azure on a A0/X-Small shared core instance. I added some code to the start page to dig out a few counters from the VM to show it’s environment.
There are a few interesting facts to highlight:
- The physical RAM of a A0 instance is only 767 MB, which really isn’t a lot
- The C:\Windows folder is only 584 MB. The difference in footprint between Nano Server and Windows is dramatically different. (C:\Program Files exist but is 0MB)
- Out of that amount of RAM, the website only used a 58 MB working set. The DNX environment is lean environment that survives pretty good on the smalest VM Azure can provide,
Why this rant about Nano Server? Well, what I’ve showed here is part of the future, where you can build solution as small services that are very lightweight and that runs in evnironments that are completly with out a UI. If your service can leverage this technology you have the ability of keeping the item price low, which is key if you are going to have to scale up to several thousands of VMs that work together.
ASP.Net5 is an exciting new piece of technology since it has the ambition of being leightweight and give you every ounce of performance. It is also a multiplatform technology which I will show you in the next post when we deploy an ASP.Net5 website on Ubuntu Linux using Mono.
//build conference – Introducing ASP.NET 5, by Scott Hanselman and Scott Hunter
ASPNET vNext on Nano Server – Nano Server Team blog
ASP.Net5 on github – documentation and code (open sourced by Microsoft)
Be sure to check out the references in the previous post