Debugging ASP.NET vNext Beta Builds with Visual Studio 14 CTP 3

Visual Studio CTP 3 has launched a while back and I was expecting to have trouble working with ASP.NET vNext beta builds. I was partially right. I wasn’t able to run the web application from Visual Studio. However, it’s still possible to debug the application and I have a workaround for you :)
2014-10-05 16:17
Tugberk Ugurlu


Today, I was working on a sample project with ASP.NET vNext. I have been working on this application without any Visual Studio IDE support but I decided to discover what Visual Studio 14 CTP 3 is bring to the table. I know that Visual Studio CTP 3 has launched a while back and I was expecting to have trouble working with ASP.NET vNext beta builds (hot from the developer machine. Find them here). I was partially right. I wasn’t able to run the web application from Visual Studio. However, it’s still possible to debug the application and I have a workaround for you :)

As I was thinking from the very beginning that I would have trouble with VS 14 CTP 3 + vNext beta builds, I started setting up my environment from the command line instead of letting the VS handle this.

image

However, Visual Studio still insisted on installing the Aplha3 builds of the K Runtime but anyways. That’s not big of a deal as long as I have the beta one as the active runtime. When I open up the solution, everything looked OK. Even the package restore was successful.

image

The build was also working. Awesome!

image

So, it was all going great till I realized that I was building with the OutputType set to "Class Library".

image

As soon as I changed it to Web Application, the build broke:

image

This is OK and expected as things have changed since Visual Studio 14 CTP 3 shipped. However, I’m unable to debug my application now. Hmm, not entirely. There are still options and I went with the easier one.  I switched back to command line and ran the application from there with "k web" command:

image

All good as you can see. Now, back to Visual Studio and press CTRL + ALT + P to bring up the Attach Process dialog box. We are looking for klr.exe to attach but you will probably see two instances of klr there. We need the one that actually hosts our application. You can find out which one is the actual host by looking at the command line arguments from the Task Manager.

image

In my case, it’s with the PID 1472. Finally, attach the process and you should be able to debug the application now.

image

image

Enjoy ;)

Exciting Things About ASP.NET vNext Series: The Ultimate Guide

As of today, I am starting a new blog post series about ASP.NET vNext. To kick things off, I would like to lay out the resources about ASP.NET vNext here which is probably going to be an ultimate guide on ASP.NET vNext.
2014-10-03 11:49
Tugberk Ugurlu


Web development experience with .NET has never seen a drastic change like this since its birth day. Yes, I’m talking about ASP.NET vNext :) I have been putting my toes into this water for a while now and as of today, I am starting a new blog post series about ASP.NET vNext (with hopes that I will continue this time :)). To be more specific, I’m planning on writing about the things I am actually excited about this new cloud optimized (TM) runtime. Those things could be anything which will come from ASP.NET GitHub account: things I like about the development process, Visual Studio tooling experience for ASP.NET vNext, bowels of this new runtime, tiny little things about the frameworks like MVC, Identity, Entity Framework.

To kick things off, I would like to lay out the resources about ASP.NET vNext here. Enjoy them and start discovering what is coming up for the web development with .NET :)

Getting Started Material

Here and There ASP.NET vNext

Development Environment and Tooling Experience

Deployment

Deep Dive

MVC Specific

Badass Repositories

KRuntime: The core of the ASP.NET vNext. Compilation, bootstraping, package discovery and all other core stuff is handled here. Do not miss on this one!

kvm: K Runtime version manager which works on Windows and Unix based systems.

MVC: Written from scratch MVC framework on top of ASP.NET vNext. This new framework unifies the efforts on ASP.NET MVC and ASP.NET Web API. So, all is in one now.

HttpAbstractions: Contains HTTP abstractions for ASP.NET vNext such as HttpRequest, HttpResponse. Also contains IApplicationBuilder and types to create your application's hosting pipeline.

Home: ASP.NET vNext Home repository where you can get a head start on ASP.NET vNext really quickly. Its README file gives you a nice guide to get your machine up and running with the new tools. It also contains tiny samples which you can run and see how things are working in no time.

KestrelHttpServer: This repo contains a development web server for ASP.NET vNext based on libuv.

Configuration: Configuration is a framework for accessing Key/Value based configuration settings in an application.

Caching: Contains libraries for caching for ASP.NET vNext. Another sign that everything is now composable.

Options: Options is a framework for accessing and configuring POCO settings. Tiny thing that makes me happy that even this thing is thought of.

SignalR-Server: ASP.NET SignalR is a is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. This repository exposes ASP.NET SignalR on top of ASP.NET vNext.

Hosting: The Hosting repo contains code required to host an ASP.NET vNext application, it is the entry point used when self-hosting an application.

Videos

INTRODUCING: The Future of .NET on the Server: Very first video on ASP.NET vNext. Join the Lesser Scotts, Hunter and Hanselman, as they introduce you to new thinking around ASP.NET and the .NET Framework. What does ASP.NET look like in 2014 and beyond? In a world of NuGets and modular frameworks, of lightweight VMs, how could ASP.NET change and get faster, leaner, meaner, and more.

DEEP DIVE: The Future of .NET on the Server: Scott Hanselman joins developer David Fowler for this Part 2 Deep Dive into what’s coming in Microsoft ASP.NET. We explore what a decoupled stack looks like, how modules plug together, what this means for performance, and more. We explore the Project codenamed “Helios” and how this new way of writing ASP.NET applications uses OWIN and plugs into IIS giving you more power and choice than ever before.

Channel 9 Live: ASP.NET Developer Q&A with Scott Hunter & Scott Hanselman: The Scotts and David Fowler answer your questions live!

The Future of ASP.NET Part I: Scott Hanselman’s awesome intro talk on ASP.NET vNext at NDC Oslo 2014 conference.

The Future of ASP.NET Part II: David Fowler and Damian Edwards Q&A session on ASP.NET vNext at NDC Oslo 2014 conference.

An Introduction to ASP.NET vNext: Awesome introduction talk by Daniel Roth at TechEd New Zealand 2014.

ASP.NET vNext 101: Another great introduction talk on ASP.NET vNext by Damian Edwards and David Fowler at dotnetConf 2014.

ASP.NET MVC 6 (now with integrated Web API!): Awesome introduction at dotnetConf 2014 by Daniel Roth on ASP.NET MVC 6 which is a new baby from head to toe. ASP.NET MVC and Web API are being combined into a single framework, ASP.NET MVC 6, for handling all of your Web UI and services. We'll learn how to use ASP.NET MVC and Web APIs in ASP.NET vNext to support connected applications for browsers, Windows Phone, Windows Store and more!

Entity Framework: Rowan Miller gives us an introduction talk at dotnetConf 2014 about Entity Framework 7 which is built on this new .NET Runtime optimized for server. Entity Framework is Microsoft's recommended data access technology for new applications in .NET. We'll explore how the current release of Entity Framework can be used to build applications. We'll also look at an early preview of EF7, a modern, lighter weight, and composable version of Entity Framework (EF) that can be used on a variety of platforms, including ASP.NET vNext, Windows Phone and Windows Store. This new version will also support targeting non-relational data stores.

ASP.NET vNext with Chris Ross: On Web Camps TV, this week Cory is joined by Chris Ross from the ASP.NET team to talk about the vNext bits of ASP.NET. The next version of ASP.NET ("ASP.NET vNext") has been redesigned from the ground up. The goal is to create a lean and composable .NET stack for building modern cloud-based apps.

ASP.NET vNext Community Standup: Meeting recordings from the weekly ASP.NET vNext Community Standup meetings, covering live community Q&A, product team discussion and the most recent updates.

ASP.NET vNext - Everything you need to know in 4 minutes!: Nice intro on new ASP.NET vNext in a short, 4 minutes video. This nicely wraps up what are the new things.

ASP.NET vNext Giriş (in Turkish): 30 minutes webcast on ASP.NET vNext by Tugberk Ugurlu in Turkish.

Dev: ASP vNext: Scott Hunter and Brady Gaster talk about ASP.NET vNext at TechEd Europe 2014

The Future of Microsoft .NET on the Server: Scott Hunter’s TechEd session on ASP.NET vNext at TechEd Europe 2014.

Podcasts

Reconciling ASP.NET vNext with Damian Edwards: Hanselman sits down with Damian Edwards and talks about ASP.NET vNext. There's been a lot of talk around ASP.NET vNext. How did development start, and what's been the thinking about how to manage a new world while still innovating on the current generation of technology? In what ways does ASP.NET vNext break from the past, and in what ways does it build on our existing power and experience?

ASP.NET vNext with Jeff Fritz: Carl and Richard chat with Jeff Fritz about ASP.NET vNext at DotNetRocks.

Evolving ASP.NET Web Development with Scott Hunter: Carl and Richard chat with Scott Hunter about how Microsoft is working to evolve web development for ASP.NET developers. Scott talks about ASP.NET vNext as well.

Herding Code 198: Damian Edwards on ASP.NET vNext, Tag Helpers and SignalR: The guys talk to ASP.NET team member Damian Edwards about ASP.NET vNext (the next version of ASP.NET), Tag Helpers, and what’s new with SignalR.

Code Samples

MusicStore: Best sample out there for ASP.NET vNext by the team. It has two projects: one is for static-rendered Music Store application and the other one is a SPA (Single Page Application). Check out this article for further information about the sample.

BugTracker: Another sample application from ASP.NET team. This one is also uses SignalR. Check out the this article for further information about this sample.

MVC Samples: Lots of tiny MVC samples that ASP.NET team is using for functional tests.

Entropy: ASP.NET vNext feature experience playground of ASP.NET team.

MvcSample.Web: ASP.NET MVC 6 sample which highlights quite a lot of its features.

KLoggy: My playground for a few cool things such as ASP.NET vNext, Gulp, Bower, AngularJS. Check it out for sure. I have big plans for this :)

conch: Nice sample on ASP.NET vNext by Mark Rendle. The repo description says "Nothing to see here. Move along". So, keep that in mind :)

vNextLanguageSupport: A sample by David Fowler that has examples of how to support different languages in the vNext project system.

AspNetVNextSamples: My repository on ASP.NET vNext samples. It’s sort of tiny right now but I’m putting this here anyway hoping that it will get big in near future.

Getting Started with ASP.NET vNext by Setting Up the Environment From Scratch

In this post, I'll walk you through how you can set up your environment from scratch to get going with ASP.NET vNext.
2014-09-28 19:08
Tugberk Ugurlu


I'm guessing that you already heard the news about ASP.NET vNext.  It has been announced publicly a few months back at TechEd North America 2014 and it's being rewritten from the ground up which means: "Say goodbye to our dear System.Web.dll" :) No kidding, I'm pretty serious :) It brings lots of improvements which will take the application and development performance to the next level for us, .NET developers. ASP.NET vNext is coming so hard and there are already good amount of resources for you to dig into. If you haven't done this yet, navigate to at the bottom of this post to go through the links under Resources.  However, I strongly suggest you to check Daniel Roth’s talk on ASP.NET vNext at TechEd New Zealand 2014 first which is probably the best introduction talk on ASP.NET vNext.

What I would like to go through in this post is how you can set up your environment from scratch to get going with ASP.NET vNext. I also tnhink that this post is useful for understanding key concepts behind this new development environment.

First of all, you need to install kvm which stands for k Version Manager. You can install kvm by running the below command on your command prompt in Windows.

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))"

This will invoke an elevated PowerShell command prompt and installs a few stuff on your machine. Actually, all the things that this command installs are under %userprofile%\.kre directory.

image

Now, install the latest available KRuntime environment. You will do this by running kvm upgrade command:

image

The latest version is installed from the default feed (which is https://www.myget.org/F/aspnetmaster/api/v2 at the time of this writing). We can verify that the K environment is really installed by running kvm list which will list installed k environments with their associated information.

image

Here, we only have good old desktop CLR. If we want to work against CoreCLR (a.k.a K10), we should install it using the –svrc50 switch:

image

You can switch between versions using the "kvm use" command. You can also use –p switch to persist your choice of the runtime and that would allow you to specify your default runtime choice which will live between processes.

image

Our system is ready for ASP.NET vNext development. I have a tiny working AngularJS application that you can find here in my GitHub repository. This was a pure HTML + CSS + JavaScript web application which required no backend system. However, at some point I needed some backend functionality. So, I integrated with ASP.NET vNext. Here is how I did it:

First, we need to specify the NuGet feeds that we will be using for our application. Go ahead and place the the following content into NuGet.config file inside the root of your solution:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
      <clear />
      <add key="AspNetVNext" value="https://www.myget.org/F/aspnetrelease/api/v2" />
      <add key="NuGet.org" value="https://nuget.org/api/v2/" />
  </packageSources>
</configuration>

Later, have the project.json inside your application directory. This will have your dependencies and commands. It can contain more but we will just have those for this post:

{
    "dependencies": {
        "Kestrel": "1.0.0-alpha3",
        "Microsoft.AspNet.Diagnostics": "1.0.0-alpha3",
        "Microsoft.AspNet.Hosting": "1.0.0-alpha3",
        "Microsoft.AspNet.Mvc": "6.0.0-alpha3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-alpha3"
    },
    
    "commands": { 
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
        "kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
    },
    "frameworks": {
        "net45": {},
        "k10": {}
    }
}

With the runtime instillation, you can have a few things and one of them is kpm tool which allows you to manage your packages. You can think of this as NuGet (indeed, it uses NuGet behind the scenes). However, it knows how to read your project.json file and installs the packages according to that. If you call kpm now, you can see the options it give you:

As you have the project.json ready, you can now run kpm restore:

image

Note that the restore output is a little different if you are using an alpha4 release:

image

Based on the commands available in your project.json file, you can run the command to fire up your application now.

image

Also, you can run "set KRE_TRACE=1" before running your command to see diagnostic details about the process if you need to:

image

My little app is now running:

image

Resources

Quickly Hosting Static Files In Your Development Environment with Node http-server

Yesterday, I was looking for something to have a really quick test space on my machine to play with AngularJS and I found http-server: a simple zero-configuration command-line http server.
2014-09-28 13:19
Tugberk Ugurlu


Yesterday, I was looking into AngularJS which is a long overdue for me. I wanted to have a really quick test space on my machine to play with AngularJS. I could just go with Plunker or JSFiddle but I wasn’t in the mood for an online editor.

So, I first installed Bower and then I installed a few libraries to get me going. I made sure to save them inside my bower.json file, too:

image

bower install angular -S
bower install bootstrap -S
bower install underscore –S

image

Then, I installed my node module to help me automate a few processes with gulp.

BTW, do you know VS has support for running you gulp and grunt tasks? Check out Scott Hanselman’s post if you don’t: Introducing Gulp, Grunt, Bower, and npm support for Visual Studio

Finally, I have written a few lines of code to get me going. The state the this tiny app can be found under my GtHub account. I was at the point where I would like to see it working in my browser:

image

As a developer who have been heavily working with .NET for a while, I wanted to hit F5 :) Jokes aside, what I only want here is something so simple that would host my static files inside my directory with no configuration required. While searching a great option for this, I found http-server: a simple zero-configuration command-line http server.

image

I simply installed it as an global npm module:

image

All done! It’s now under my path and I can simply cd into my root web site directory and run http-server there.

image

Super simple! It also observes the changes. So, you can modify your files as the http-server serves them. You can even combine this with LiveReload + a gulp task.

Elasticsearch Installation and a Few Core Concepts

So, I have been having my way with Elasticsearch for a few weeks now and it's time for me to blog about it :) In this post, I will only highlight a few things here which were useful to me at the beginning.
2014-09-25 15:01
Tugberk Ugurlu


So, I have been having my way with Elasticsearch for a few weeks now and it's time for me to blog about it :) I hear what you say :) This is yet another 101 blog post but settle down :) I have a few selfish reasons here. Blogging on a new technology is a way for me to grasp it better. Also, during this time, I have been also looking into Azure Search, an hosted search service solution by Microsoft. You should check this service out, too if what you want is to have an easily scalable hosted search service solution.

OK, what were we talking about? Oh yes, Elasticsearch :) It's awesome! I mean it, seriously. If you haven't looked at it, you should check it out. It's a search product which makes data search and analytics very easy. It's built on top of famous search engine library Apache Lucene. Elasticsearch also has a great documentation. So, I will only highlight a few things here which were useful to me at the beginning.

Setting it Up

To get started with Elasticsearch, you can download it from here. At the time of this writing, version 1.3.2 was the latest version. What you need to do is fairly simple: download the zip file, extract it, navigate to bin directory and run Elasticsearch from the command line.

1-Screenshot 2014-09-25 13.20.48

As we didn't specify any configuration values, Elasticsearch started with the configuration defined inside the /config/elasticsearch.yml file. If you didn't touched that file either, it will be exposed through localhost:9200. Elasticsearch server is exposed to the World through its HTTP API and when you send a GET request to the root level, you will get the server info:

2-Screenshot 2014-09-25 13.23.47

You can also see inside the response that the node even assigned itself a random name: Mole Man in this case. You can start working with this elasticsearch node using your choice of an HTTP client but I really recommend installing Marvel which ships with a developer console that allows you to easily issue calls to Elasticsearch’s HTTP API. To install marvel, you need to run the following command which you are under the elasticsearch/bin path:

plugin -i elasticsearch/marvel/latest

After you are done with the installation, you should restart the server and from there, you can navigate to localhost:9200/_plugin/marvel/sense/index.html on your favorite browser:

3-Screenshot 2014-09-25 13.43.02

Now, you can start issuing request to you Elasticsearch server right from your browser:

4-Screenshot 2014-09-25 13.47.13

The best part of this plugin is its autocomplete support while you are construction queries:

5-Screenshot 2014-09-25 13.49.29

It can even understand and provide you the options for your type fields which is pretty useful. Before going deeper, let's learn e few fundamentals about Elasticsearch.

Basics 101

When working with Elasticsearch, you will come across a few core concepts very often. I think knowing what they are beforehand will help you along the way.

Index is the container for all your documents. Each document inside your index will have a few shared properties. One of those properties is type. Each document inside your index will have a type and each type will have a defined mapping (sort of a schema). The type and its mapping is not required to be defined upfront. Elasticsearch can create the type and its mapping dynamically. However, there are lots of useful things you can achieve with altering the default mapping such as changing the analyzer for a field.

At first glance, it seems that we can only search on types but that's not the case actually. You can even search the entire Elasticsearch node if you want:

6-Screenshot 2014-09-25 14.08.02

I have a few indexes created here and those indexes have documents in one or multiple different types. When I search for a word "madrid"  here, I got 568 hits throughout the node. I have some hits as movie type from movies-test index and some hits as status type from my_twitter_river index. This could be pretty powerful depending on your scenario if you embrace Elasticsearch’s schema free nature. We can also search on one index and that would give us the ability to search for the types under that particular index.

I mentioned that each type has its mapping. You can see the mapping of a type by sending a GET request to /{index}/{type}/_mapping:

7-Screenshot 2014-09-25 17.23.17

Twitter River Plugin for Elasticsearch

If you are just getting started with Elasticsearch, what I recommend for you is to get some data in using the Twitter River Plugin for ElasticSearch. After you configure and run it for a few hours, you will have insane amount of data ready to play with. 

8-Screenshot 2014-09-25 17.28.10

Resources