Build your beta4 MVC 6 app from scratch using Code gen – Part 1

There is a newer updated blog for this here.

UPDATE!! 2/8/2015

The kre home is being renamed again. I will update these posts that referred to the new .dotnet home for runtime as that appears to be going away.


In this post we rely on the built-in code generation utilities that come with ASP.NET 5 to build our app from scratch. I am doing this on Windows 7 and using Visual Studio 2015 CTP.

As usual we will use the latest code bits available from the nightly builds.

Follow this post if you have not installed the newly renamed dotnet runtime, Setting up beta4 dotnet runtime on your machine (i.e. don’t have a .dotnet directory in your home directory).

Let’s start by making sure we have the latest CoreCLR available. Open PowerShell and in your .dotnet bin directory run the dotnetsdk script. I’ve got the latest as you can see.



Create an Empty ASP.NET 5 Web Application called FromScratchWebApp.



They call it empty for a reason, about the only thing in there is a bare bones Startup class and project.json file. We are going to add just enough to run our code generating utilities and let them do most of the work. Make the bottom of your project.json file look like this.

"dependencies": {
		"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
		"Microsoft.AspNet.Hosting": "1.0.0-*",
		"Microsoft.AspNet.Diagnostics": "1.0.0-*",
		"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-*",
		"EntityFramework.Commands": "7.0.0-*",
		"EntityFramework.SqlServer": "7.0.0-*"
	"frameworks": {
		"aspnetcore50": { }
	"commands": {
		"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
		"gen": "Microsoft.Framework.CodeGeneration",
		"ef": "EntityFramework.Commands"

Modify the Configure method in the Startup class to look like this:

        public void Configure(IApplicationBuilder app)

That’s enough coding for now, build your app making sure there are no build errors. I want to point out how simple our solution tree looks right now. Notice we have pulled in the latest beta4 code from nightly build.
Let’s look at using the commands we defined in our project.json file. Open a command window and navigate to the .dotnet directory in your User home. Run the temp-set-envars.cmd file to set up our runtime environment in this session.

setupruntimeenv Now navigate to the project folder that contains our project.json file.

Type k  --version and this should display the runtime we think we are using.



Ok, that matches the latest I saw in PowerShell so we are looking good.

Now type
k   ef


These are the Entity Framework 7 commands available but we will not use in this post series.

Now type
k   gen
These are the Code Generator commands that will be available to us.

Finally, lets run the best k command we have available,
k   web
This will host our app with Web Listener, a light weight web server. You should see the response Started in the command shell.
Open a web brower and enter http://localhost:5000/
I’m using IE 11 here.
We aren’t relying on Visual Studio 2015 to run the app but we can still make use of it to monitor it. Use Ctrl+Alt+P to attach to the dotnet.exe process (CoreCLRE runtime). You may need to restart Visual Studio to run as admin.

Use Ctrl+Alt+O to view the output of our process.
Note the output shows are are running with
dotnet-coreclr-win-x64.1.0.0-beta4-10981 as the runtime.

In the next post we will use the gen command to spin up some code.