Using the NeoSample ASPNET 5 Starter App on GitHub with latest nightly builds

Update 4/3/2015

See the latest post on this here.

I’ve updated globally to Bower 1.4 on Windows 8.1 machine for this post.

npm update -g bower

NeoSample-ASPNET5 now uses Entity Framework InMemory datastore provider by default so just download and run on the latest CLR x86 runtime. You can switch to the SQL Server provider easily with a few lines of code.

The NeoSample-ASPNET5 Starter app is up on GitHub.
This is the sample based on the ASPNET 5 Starter App created by the Visual Studio 2015 template which has been modified to compile against the current beta4 nightly builds.

Always check the readme to see current status, UP means you can compile and run with the latest aspnetvnext nightly builds, DOWN means I’m waiting on something to be resolved.

By default the app now uses the EF InMemory provider so you do not need to apply the CreateIdentitySchema migration to use. Switch to SQL Server and apply migration when you need to.

Here is some guidance on setting up and running the app.

Currently the app does not run with Visual Studio 2015  CTP 6 because of the dnx naming that was done. The next release of VS2015 should allow the opening and running of the NeoSample-ASPNET5.

This is my setup but doesn’t mean everything is needed, I just want you to have any tools you may need in your tool belt.

If you setup Visual Studio 2015 CTP6 and create an ASP.NET 5 Web App you should wind up with a .k directory with packages and runtimes under it. I like also having the .k\bin folder which holds the kvm.cmd and kvm.ps1 files. This allows you to manage the installation of the dotnet runtimes. Use this post but instead of dotnetsdk use kvm. Also the default directory is now .k and not .dotnet.
newkvm

 

Running kvm setup now installs the version manager into your user profile directory (in .k\bin) and adds the KRE_HOME to your user profile.

kvmsetup

envvariables

 

The latest runtime 32-bit Asp.Net 5.0. will be used when we  open the solution using VS2015 CTP 6 which we do later.

Navigate your .k\bin folder holding kvm files and type

kvm list

This should show you a list of runtimes installed in .k and which one is active.

kvmlistdotk

Let’s upgrade to the latest x86 CLR. You can see the command to do that is

kvm upgrade -arch x86 -r CLR -a default

Very important that the latest runtime shows as active and has default alias as shown above. Also VS2015 prefers we have x86 CLR as active and default to open the solution.
No go back to the Environment Variable window as seen above and put the path to the runtime in variable Path under User variables. My Path looks like this.

C:\Users\Glenn\.k\bin;C:\Users\Glenn\.k\runtimes\kre-clr-win-x86.1.0.0-beta4-11132\bin;:.

Notice I have a path to my .k\bin folder so I can run the kvm command from anywhere. The runtime bin makes sure we run the correct k command when we are in our project directory.
Close all command prompt windows and open a new one so you pick up the latest environment settings.

You should also be able to type

k --version

and it will display the runtime version you are using. I see

1.0.0-beta4-11132

on my machine.

Now let’s download the sample from github NeoSample-ASPNET5 here. You’ll see download zip file on bottom right.

Open the zip file and place in one of your folders.

Now let’s go to the folder in the command prompt window. Find the project directory for NeoSample under src directory. On my machine I find it here

c:\projects\2015\NeoSample-ASPNET5-master\src\NeoSample>

Now type

k --version

This should still show the current runtime version.
If all looks good so far type (enter multiple times until no package complaints)

kpm restore

kpm restore makes sure all the packages are downloaded and installed. You should see alot of activity after entering this.

Now type

k ef -h

This should display the Entity Framework version you are using and it should be a beta4 version.
I see this but you should have a later version by now

7.0.0-beta4-12340

If we now go to the project directory under test, on my machine it is

c:\projects\2015\NeoSample-ASPNET5-master\test\NeoSample.Tests

type

kpm restore

to load all packages. You may need to run a few times.
Now type

k test

this should run the tests that are defined and one should fail.
runtest
Great we just ran the test project in the latest run time using the k command.

Now I open the solution in VS2015 CTP 6 I see
solnopened

You need to set the SQL Server connection string you will be using in the DbContext class ApplicationDbContext if you decide to apply the migration to SQL Sever. By default is using the InMemory provider to load the EF data model.

And if I open up project properties I can set to the current runtime under Application tab and Debug tab.
projprop1

projprop2
Note I selected web for debug profile. I can now very easily step through the code with the debugger while logging to same console window. Nice.

 

By default the Entity Framework InMemory datastore is used. This is sufficient for running the app. To use SQL Server make the following code changes to the NeoSample project.

In the ApplicationDbContext class under DbContexts folder in the OnConfiguring method, comment out the call to UseInMemoryStore and uncomment UseSqlServer. Set the connection string for UseSqlServer for your database.

In Startup class in the ConfigureServices method comment out .AddInMemoryStore() and uncomment .AddSqlServer().

Back in command prompt under src\NeoSample directory type

k ef migration list

You should see

20150223170858_CreateIdentitySchema

This is the migration I created already for you.
Now lets apply this migration and create the database with the following command

k ef migration apply CreateIdentitySchema -c ApplicationDbContext

We just applied the migration in the database to our database. This is the identity schema that tracks accounts for login.
Now we should be able to run the app right from here, type

k web

This will host our app and start it for us.
Now open url

http://localhost:5000/

in a browser.
I see the app come up and I can even register using the InMemory datastore.
registered

Life is good.