Microsoft unvelied ASP.Net vNext in May of this year, and it has been developed heavily ever since. ASP.Net vNext represents the future of ".Net on the Server", so I though tI might prepare this guide for actually getting it up and running on a server (which is not quite as striaght forward as you may expect).
Windows Server 2012 R2 Data Centre (Azure instance, A1).
The following applies to Windows Azure:
Launch a new Virtual Machine
Login to the Azure Managemenet Portal (manage.windowsazure.com), click on the Virtual Machines tab.
Click the "+ New" button to create your new VM that we will be working with:
This will spin up your new instance. In my experience, this may take about 5-10 minutes.
Azure randomizes the ports / endpoints it opens up on new instances, to make it trickier for hackers, so you'll need to click on the server, then the "end points" tab to find our what port to use for your PowerShell / Remote Desktop connections.
Log in to your server
Using remote desktop, and the hostname and port number from the orevious screen, connect to your server. You will be presented with the Server Manager:
From the "Manage" button in the top right of the screen, click "Add Roles and Features"
We want to select "Application Server" and "IIS" to support vNext.
On the next page, we want to make sure that ASP.Net 4.5 i selected.
And that IIS is selected again as a role service for "Application Services" (confusing eh?).
The defaults for the next screen "Role Services" for the "Web Server Role" are all fine.
Click install, and grab a coffee.
The default locked down version of Internet Explorer is the most frustrating thing on the planet, so download Chrome to avoid the insidious "Content Warning" dialogues.
ASP.Net vNext is open source, so that means we can build everything from scratch. This gives us more insight into how everything works, and kind of makes you feel like a real programmer. Download git for windows here. Select the "Use Git and optional Unix tools from the Windows Command Prompt" option to make it as easy as possible to use Git.
Setting up for source
Open a Powershell prompt, and run the following commands:
cd C:\ mkdir src cd src
### Clone and build the "K version manager" (KVM)
git clone https://github.com/aspnet/kvm.git cd kvm .\build.cmd
The output should look like:
PS C:\src\kvm> .\build.cmd Downloading latest version of NuGet.exe... Installing 'KoreBuild 0.2.1-beta1-10038'. Successfully installed 'KoreBuild 0.2.1-beta1-10038'. Installing 'Sake 0.2'. Successfully installed 'Sake 0.2'. info: Target default info: Target pre-clean info: Target clean info: Target post-clean info: Target validate info: Target initialize info: Target copy-kvm info: Copying kvm.cmd info: Copying kvm.ps1 info: Copying kvm.sh info: Copying kvmsetup.cmd info: Updating C:\src\kvm\artifacts\kvm.ps1 info: Updating C:\src\kvm\artifacts\kvm.sh info: Target compile info: Target test-compile info: Target test info: Target package-prepare info: Target package
Install the K Runtime (KRE)
This is most easily done by using the K Version Manager, which we just built.
cd artifacts PS C:\src\kvm\artifacts> .\kvm.ps1 install latest Determining latest version Downloading KRE-CLR-x126.96.36.199-beta1-10465 from https://www.myget.org/F/aspnetvnext/api/v2 Unpacking to C:\Users\msgooroo\.kre\packages\temp Installing to C:\Users\msgooroo\.kre\packages\KRE-CLR-x188.8.131.52-beta1-10465 Adding C:\Users\msgooroo\.kre\packages\KRE-CLR-x184.108.40.206-beta1-10465\bin to process PATH
We now have the k runtime installed (beta-1 at the time of writing). This means we can now run K based commands, lik e"k --version" to see that we have infact installed the latest version of k.
Clone the ASP.Net vNext Demo App "BugTracker"
PS C:\src\kvm\artifacts> cd C:\src PS C:\src> git clone https://github.com/aspnet/BugTracker.git Cloning into 'BugTracker'... remote: Counting objects: 438, done. remote: Compressing objects: 100% (4/4), done. Receiving objects: 100% (438/438), 329.87 KiB | 479.00 KiB/s, done. remote: Total 438 (delta 0), reused 0 (delta 0) Resolving deltas: 100% (219/219), done. Checking connectivity... done.
A few notes on this: The MusicStore application should be built using .\build.cmd, but this has a dependency on Visual Studio, which we would rather not have have to worry about.
Use "K Package Manager" to install dependencies
One of the great things about vNext and the whole "K" environment is its ability to resolve dependencies automatically by using the "kpm restore" command.
> cd BugTracker\src\BugTracker > git checkout dev > kpm restore > k run
Open a browser, and navigate to: http://localhost:5003/
And you may be confronted with this beautiful error:
An unhandled exception occurred while processing the request. MissingMethodException: Method not found: 'System.Runtime.Versioning.FrameworkName Microsoft.Framework.Runtime.IApplicationEnvironment.get_TargetFramework()'. Microsoft.AspNet.Mvc.Razor.Compilation.RoslynCompilationService.Compile(String content)
Install .Net 4.5.2
All this K stuff needs the latest version of .Net which is not installed by default on Windows Server 2012 R2, so we will need to download and install it.
It will probably also require that you reboot.
Lets try again
cd C:\src\BugTracker\src\BugTracker kpm restore k run
We can then open our browser to: http://localhost:5003/ to see this lovely screen:
It may not be pretty (or fast), but its a real life ASP.Net vNext application running on Windows Server 2012 R2 off the latest build of K / vNext.
Method not found: 'Void Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions
MissingMethodException: Method not found: 'Void Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions..ctor(Microsoft.CodeAnalysis.OutputKind, System.String, System.String, System.String, System.Collections.Generic.IEnumerable`1<System.String>, Boolean, Boolean, Boolean, System.String, System.String, System.Nullable`1<Boolean>, Int32, UInt64, Microsoft.CodeAnalysis.Platform, Microsoft.CodeAnalysis.ReportDiagnostic, Int32, System.Collections.Generic.IEnumerable`1<System.Collections.Generic.KeyValuePair`2<System.String,Microsoft.CodeAnalysis.ReportDiagnostic>>, Boolean, Microsoft.CodeAnalysis.DebugInformationKind, Microsoft.CodeAnalysis.SubsystemVersion, System.String, Boolean, Microsoft.CodeAnalysis.XmlReferenceResolver, Microsoft.CodeAnalysis.SourceReferenceResolver, Microsoft.CodeAnalysis.MetadataReferenceResolver, Microsoft.CodeAnalysis.MetadataReferenceProvider, Microsoft.CodeAnalysis.AssemblyIdentityComparer, Microsoft.CodeAnalysis.StrongNameProvider)'.
This means your porbably forgot to do hte "git chekout dev" at the root of the BugTracker project, which will update the NuGet.config to point to "https://www.myget.org/F/aspnetvnext/api/v2/" rather than "https://www.myget.org/F/aspnetmaster/api/v2".
The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNet'
System.InvalidOperationException: C:\src\BugTracker\src\BugTracker\Program.cs(4,24): error CS0234: The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNet' (are you missing an assembly reference?)
This is probably because K is pointing at the wrong version. In this case, run the following:
> C:\src\kvm\artifacts\kvm.ps1 install latest
Which should produce the following output:
Determining latest version KRE-CLR-x220.127.116.11-beta1-10465 already installed. Adding C:\Users\msgooroo\.kre\packages\KRE-CLR-x18.104.22.168-beta1-10465\bin to process PATH
Verify that the latest version is in fact being run with:
> k --version 1.0.0-beta1-10465