Book Updates

The first edition of the book "Delivering Mobile-Friendly WebSites With MVC4" was built around the MVC4 Beta release. On May 31, 2012, Microsoft released the VS2012 Release Candidate and MVC4 Release Candidate. On August 15, 2012, Microsoft released the final VS2012 RTM Version and the MVC4 RTM Version.

With each of these releases came a few changes. With regards to my book, there are relatively few breaking changes. The Bundling and Minification section in Chapter 4 changed significantly from the Beta to the Release Candidate, and the Recipe feature found in the Beta Release is totally gone in the RC and RTM versions. See below for code changes and more discussion of MVC4 Recipes.

I've released a Third Edition of the book which is available on Amazon. If you have the Second Edition, the changes are very minimal and not worth worrying about. If you have the First Edition, Chapter 4 has a lot of changes, so I've decided to release that as a PDF for my readers in 8.5x11 format. That way, if you have an existing book, you can easily print it out and update your copy. If you've bought a first or second edition book and would like to get an updated eBook version, contact me and I'll do my best to make that happen.

In the meantime, I'll post changes and updates here as I find them.

Lyle


Changes to Chapter 4: Building a MVC Mobile WebSite

Recognizing Mobile Devices – Page 23

There is some code that is inserted into the Application_Start event. The code that is inserted has not changed, but the before and after code lines are different in the Release Candidate.

Creating a Mobile Layout Page – Page 27

"When you open that up, you will see a few lines that look like this:"

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

Creating a Custom Bundle – Page 29 (Significant changes….)

"Let’s see how we can create some custom bundles in our application by adding a bit of custom code in the new MVC4 BundleConfig.cs file located in the App_Start folder. We'll modify the RegisterBundles function to handle that. We’ll create a couple of custom bundles for our mobile version and specify just the files we are interested in.

Here's the code:"

public static void RegisterBundles(BundleCollection bundles) 
{
  [… existing bundle code goes here… ]
  bundles.Add(new ScriptBundle("~/bundles/MobileJS").Include(
    "~/Scripts/jquery.mobile-1.*",
    "~/Scripts/jquery-1.*"));

  bundles.Add(new StyleBundle("~/Content/MobileCSS").Include(
    "~/Content/jquery.mobile.structure-1.1.0.min.css",
    "~/Content/jquery.mobile-1.1.0.css"));

}

We've given these bundles a unique name so we can reference them in our mobile layout files.

If you are writing and debugging your own JavaScript and including those in your bundles, you may want to control when that code gets minified so that it's easier to debug. If the compilation tag in your web.config is set to debug=true, no minification will take place. Alternatively, you can explicitly set the BundleTable.EnableOptimizations tag in your code in RegisterBundles, and that will control it as well and will override the web.config settings.

There are no _Layout.cshtml file changes now.

_Layout.Phone.cshtml file changes:

BEFORE:
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
AFTER:
@Styles.Render("~/Content/MobileCSS")
@Scripts.Render("~/bundles/MobileJS")
@Scripts.Render("~/bundles/modernizr")
@*@Scripts.Render("~/bundles/jquery")*@
@*@RenderSection("scripts", required: false)*@


End of Chapter 4 Summary

The entire section about using a recipe may have to be eliminated or updated once I figure out what's happening with Recipes.


Recipe Changes

The ASP.NET MVC4 RoadMap documentation hinted that Recipes would be relocated at some point:

From the ASP.NET MVC 4 RoadMap

The ASP.NET MVC 4 Beta also contains a couple of experimental features that were included to get early feedback. These features won’t be ready for the final MVC 4 release and will be removed after the Beta. However, they do lay a foundation for future work.

  • Recipes: Recipes are a way to deliver tooling via NuGet packages in order to automate a task within a project. For example, recipes can be used to replace the existing Add Area, Add Controller, and Add View dialog boxes. Recipes can also add completely new functionality. Although we shipped support for recipes in Beta, we think recipes are a more natural fit for NuGet. Therefore, we'll move recipe support out of the MVC 4 release and have it supported by NuGet in a future release.

Unfortunately, they have now removed this feature from the MVC4 Release Candidate, and I have been unable to find any way to bring it back any other way. Supposedly, it will be released in the future, but I don't have any way of knowing when, where, or how. I've posted several questions and comments to Microsoft, but don't have any official answer.


Using the FoodTruck without the Recipe Feature

The FoodTruck application for creating lots of code quickly that we looked at in Chapter 11 is built on the MVC4 recipe framework, so that code will not work from within an MVC3 or MVC4 RC project. However, there is a nifty little feature that I added in the recipe that will allow you to use it anyway. To use this application, install the package by going to the Package Manager Console, and running the command "Install-Package LCI.FoodTruck.MVC4".

It's installed now, but you won't see it on any popup because the "Recipe" submenu does not exist - you'll have to manually go find and run the executable yourself. Locate the Packages folder for your project – usually it is right beside your project folder. Look in the Packages\LCI.FoodTruck.MVC4.*\recipes folder, and you should see both a DLL and an EXE file. The DLL is what is used by MVC4 Beta Recipes. However, you can run the stand-alone EXE file outside of Visual Studio. Everything works the same, except that you have to fill in the Path and the Namespace yourself on the Generate Code page.

Once you generate your code, that new code will not be included in your project (because this wasn't opened by the project), so you will have to go into the project yourself and include the files. Click on the "Show All Files" icon in your Solutions Explorer and you should see them in your folder. Right click on each file and choose the option "Include In Project". With this method, you should be able to generate the same models, views, and controllers that you could generate for MVC4 Beta.


Facebook Twitter Amazon Give Klout!
© 2017 Luppes Consulting, Inc.
Switch To: Desktop View Tablet View Phone View Default View