Getting Started with ASP.NET5.0 and the DNX Framework

I'm updating my Android SDK packages.

While I'm waiting, I'm going to install the latest DNX and aspnet5.0. It's a clean VM. No Visual Studio installed. Just Xamarin Studio, so should be a good clean install experience. Well. I was almost right.

If you want to know more, go to https://github.com/aspnet/home#upgrading-dnvm-or-running-without-visual-studio

From an Elevated command prompt (run as administrator), enter the following:

 

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"

 

 

Then close the CMD prompt, and start a new cmd prompt.

Check to see if dnwm was installed correctly.

 

Where dnvm

 

And I get the location where it is setup:' C:\Users\micheal\.dnx\bin\dnvm.cmd

Now run dnvm to see the OOBE.

So, I get a really cool text ascii art. Excellent.

I really need a bigger command prompt window. Screen buffer height and windows size to 140. Also change the colors to dark blue and yellow. And fix that horrible font.

That's better.' Let's install a DNX.

 

dnvm install

 

Well that didn't work. So, I need to say what version to install. Let's go with latest stable version of dnx.

 

dnvm install latest

 

That's better. We are off to the races'

Now we are done. Lets' get some help on dnvm

 

dnvm help install

 


 

dnvm install

' Installs a version of the runtime

 

usage:

' dnvm install [<VersionNuPkgOrAlias>] [-arch <Architecture>] [-r <Runtime>] [-a <Alias>] [-f] [-Proxy <Proxy>] [-NoNative] [-Ngen] [-Persis

tent] [-Unstable]

 

options:

' <VersionNuPkgOrAlias> The version to install from the current channel, the path to a '.nupkg' file to install, 'latest' to

install the latest available version from the current channel, or an alias value to install an alternate

runtime or architecture flavor of the specified alias.

' -arch The processor architecture of the runtime to install (default: x86)

' -r The runtime flavor to install (default: clr)

' -a Set alias <Alias> to the installed runtime

' -f Overwrite an existing runtime if it already exists

' -Proxy Use the given address as a proxy when accessing remote server

' -NoNative Skip generation of native images

' -Ngen For CLR flavor only. Generate native images for runtime libraries on Desktop CLR to improve startup time. This option

'requires elevated privilege and will be automatically turned on if the script is running in administrative mode. To opt-out in administrative mode, use -NoNative switch.

' -Persistent Make the installed runtime useable across all processes run by the current user

' -Unstable Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.

 

remarks: A proxy can also be specified by using the 'http_proxy' environment variable

So, Let's see where it put out dnx stuff. Navigate to %userprofile%\.dnx\runtimes

And have a look at the environment variables:

Let's clone some stuff. Have I git installed yet?

 

Z:\>git

'git' is not recognized as an internal or external command,

operable program or batch file.

 

Nope, let's get it

'https://windows.github.com/

I don't remember this ever been so easy!

Start a Git Shell from the desktop.

That't better

Let's clone the ASPNET

D:\Developer>mkdir aspnet

D:\Developer>cd aspnet

D:\Developer\aspnet>git clone https://github.com/aspnet/Home.git

Cloning into 'Home'...

remote: Counting objects: 1150, done.

Receiving objects: 100% (1150/1150), 628.01 KiB | 413.00 KiB/s 0

Receiving objects: 100% (1150/1150), 702.31 KiB | 413.00 KiB/s, done.

Resolving deltas: 100% (668/668), done.

Checking connectivity... done.

 

D:\Developer\aspnet>cd Home\samples

 

D:\Developer\aspnet\Home\samples>cd latest

 

D:\Developer\aspnet\Home\samples\latest>cd ConsoleApp

 

D:\Developer\aspnet\Home\samples\latest\ConsoleApp>dnu restore

Restoring packages for D:\Developer\aspnet\Home\samples\latest\ConsoleApp\project.json

' GET https://www.myget.org/F/aspnetvnext/api/v2/FindPackagesById()?Id='System.Console'.

' GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Console'.

' OK https://nuget.org/api/v2/FindPackagesById()?Id='System.Console' 2192ms

 

 

 

Now we have dnx

D:\Developer\aspnet\Home\samples\latest\ConsoleApp>dnx

Microsoft .NET Execution environment v1.0.0-beta4-11566

 

Usage: dnx [options]

 

Options:

' --appbase <PATH>' Application base directory path

' --lib <LIB_PATHS> Paths used for library look-up

' --debug ' Waits for the debugger to attach before beginning execution.

' -?|-h|--help Show help information

' --version Show version information

' --watch ' Watch file changes

' --packages <PACKAGE_DIR> Directory containing packages

' --configuration <CONFIGURATION>' The configuration to run under

' --port <PORT> ' The port to the compilation server

Something I didn't get. You have to run dnvm upgrade or dnvm use default -p to set the path.

Let's run it.

 

D:\Developer\aspnet\Home\samples>dnvm upgrade latest

Determining latest version

'dnx-clr-win-x86.1.0.0-beta4' is already installed.

Adding C:\Users\Micheal\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin to process PATH

Adding C:\Users\Micheal\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin to user PATH

Updating alias 'latest' to 'dnx-clr-win-x86.1.0.0-beta4'

 

Now, navigate to, and run the console app.

 

D:\Developer\aspnet\Home\samples>cd latest\ConsoleApp

 

D:\Developer\aspnet\Home\samples\latest\ConsoleApp>dnx . run

Hello World

 

Sweet jesus, it ran!

Let's try the HelloWeb Sample:

 

D:\Developer\aspnet\Home\samples\latest\ConsoleApp>cd ..\HelloWeb

 

D:\Developer\aspnet\Home\samples\latest\HelloWeb>dnx . web

System.InvalidOperationException: No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' has been registered.

at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)

at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider)

at Microsoft.AspNet.Hosting.Program.Main(String[] args)

 

Not sure what this is about. I though I installed latest? I googled it on bing, and found this:
http://stackoverflow.com/questions/30013929/service-missing-for-type-microsoft-framework-runtime-iapplicationenvironment

I had a similar issue when trying to run from the \samples\latest folder instead of \samples\1.0.0-beta4 folder. Simply trying again from where I was supposed to be worked.

So, use the 1.0.0.-beta3 not the [latest] like I have above. Change to the beta4 path and run

D:\Developer\aspnet\Home\samples\1.0.0-beta4\HelloWeb>dnx . web

Started

Yah!

Browe to localhost:5001

Finally, HelloMVC

 

D:\Developer\aspnet\Home\samples\1.0.0-beta4\HelloMvc>dnx . web

Started

 

And, what do you know? My Android SDK's are just finished. Brilliant.

P.S. I have since found out that if you upgrade to the unstable branch (-u), that running the above HelloWeb and HelloMVC in the [latest] folder works just fine. More about this in another post.

Written on May 23, 2015