Use NuGet package restore to simplify code sharing

Here’s a quick post on how and why you want to consider using NuGet package restore.

First, if you’re unfamiliar with NuGet, it’s basically “add reference” to external software projects (typically open source ones such as jQuery, but also for Microsoft ones such as Entity Framework). You definitely need to check out David Ebbo’s post introducing it. NuGet will change the way you develop.

Now when using NuGet it maintains a packages folder near your solution file. For things like ASP.NET MVC that heavily leverage NuGet, you’ll see this folder is very large. It’s usually much larger than your project itself in the beginning.

If you write small projects and share them out as compressed files (e.g. zip’s), and size matters to you, you might want to consider enabling NuGet package restore (off by default) for those projects and delete the packages folder before zipping and sending it out.

As an example, with a typical MVC 4 project, the “raw” content is 680 KB. After doing a build and counting the packages folder you’ll see it jumps to 16.9 MB. If that helps you significantly, then it’s probably a good idea to use package restore.

Three things have to happen to use NuGet package restore. Continue reading

Create new ASP.NET MVC views the easy way

As an instructor at DevelopMentor, I have the unique opportunity to watch many developers experience ASP.NET MVC for the first time. This typically goes through several stages:

  1. Extreme Interest (the web is exciting again!)
  2. Confusion (where does the view go again? wait, what’s routing?)
  3. Shock (you have got to be kidding, forearch in the html file?)
  4. Loss (surely there are some drag-and-drop controls, right… right?)
  5. Acceptance (OK, I will learn HTML and CSS after 10 years of working on the web)
  6. Joy and Freedom (How could I have ever used webforms?)

I rarely hear developers who’ve adopted MVC returning to webforms voluntarily. But not everyone makes it to level 6 of MVC enlightenment. So here is an article to help the new comers make it across step 2 more easily as well as help the advanced MVC developers be more productive. Continue reading

Screencast: ViewBag and View Data in ASP.NET MVC

In this screencast I discuss the ViewBag and ViewData properties in ASP.NET MVC. We look at how they can be used to pass data (both simple and complex) from controller action methods down to razor views.

Download the code:

Understanding the MVC Project Folder Structure (ASP.NET MVC Foundations Series)

Here’s a short screencast I did on understanding the ASP.NET MVC folder structure.  As you will see, MVC uses the philosophy of convention over configuration. There are many benefits to this. You simply drop a file here or there, give a class a certain name, etc, and things start to happen. But you must understand how MVC expects you to layout your project.


Preventing JavaScript Files from Loading Multiple Times

This post is about ensuring that you do not execute a particular JavaScript file more than one time. Let’s start by asking:

What happens if you link to a js file twice in your page?

Here is a contrived example.

Notice that we are including bad-example.js twice. Do modern browsers somehow realize they loaded this file already and skip this? Not yet, as we’ll see!

Imagine bad-example.js had this code in it. Continue reading

Asynchronous Programming in .NET 4.5 (Video)

Here’s a recording of a webcast I did for DevelopMentor covering .NET 4.5 and .NET 4 asynchrouns programming concepts, including Task<T>, async, and await.


PS – Be sure to watch it in 720p quality.