Scott Hanselman

This Developer's Life 2.0.5 - Typo

September 19, '11 Comments [10] Posted in Podcast
Sponsored By

Episodes 2.0.5 - Typo

Who cares about typefaces and why should you? Well, these guys do and you should start caring. Rob and Scott explore the world of reading online with one of the godfathers in the world of typeface and fonts.

In this episode we talk to Bill Hill, the bearded Scotsman who created ClearType and Geoffrey Grosenbach, notable typeface enthusiast.

I'd also like to encourage you to check out the last two episodes of This Developer's Life. We realize this isn't your typical podcast. It's not very technical, and it's not packed with information. We mean this show as an antidote to the usual technical talk shows as we try to dig more into issues and emotions that affect developers. We try to get to the center core of the developer and what makes them tick. Give us a listen and if you like the show, please review us on iTunes and Subscribe.

Download Episode 2.0.5 "Typo" here or listen online.

Also, please check out our last two shows you might have missed. We're very proud of how they turned out.


Episode 2.0.4 - Taste

2.0.4 Taste

What is taste? What is style? Do you have it? Scott and Rob have no idea what it is or how to get it - but they know it's important. In this show they talk to a designer who flexxes his good taste for a living - and a developer who is committed to spreading good taste where he can.

 


Episode 2.0.3 - Education2.0.3 Education

Scott and Rob discuss the value of a degree - and talk to two developers who used their passion to pull them through school and into their careers.

 


I hope you enjoy the show as much as Rob and I enjoy making it.

Again, big thanks to DevExpress. The bandwidth and other costs are picked up DevExpress and CodeRush! Visit them and thank them on Twitter.

This Developer's Life is brought to you by CodeRush for Visual Studio.

This Developer's Life is brought to you by CodeRush for Visual Studio.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

New Tools and New Content - ASP.NET, Visual Studio 11 Web and .NET 4.5 Developer Preview (with commentary)

September 16, '11 Comments [48] Posted in ASP.NET | ASP.NET Ajax | ASP.NET MVC | IIS | Mobile
Sponsored By

ASPNET_vNextWhile all of you Build attendees are making me feel bad because you have a fancy Tablet and I don't (sell me yours!) the folks over here in the "Angle Brackets Team" (I'm trying out some new names. One will stick.) have been busy.

Here is a summary of all the items from our team that have been announced and shown at Build this week, all of this will be publicly available today (9/16) along with a some narrative and asides from yours truly.

They are listening

One of the things I am am personally enjoying in working daily with this build of Visual Studio is that there's dozens (hundreds) of little "mental speed bumps" that are smoothed over. A lot of thought was put into workflow and common scenarios in order to, well, get out of a developer's way.

Another constant source of happiness on my part is the team's realization that not everyone can upgrade their Visual Studio, so you can round trip your projects and solutions. I can use Visual Studio 11 Developer Preview and open a .NET 4 application, save the project, and then open it in Visual Studio 2010 and it'll just work. As it always should have. Teams can mix and match and the beta guy can  be wacky without checking in solution files that will break the other folks.

By the way, have you seen our new org chart?

Our new org chart

Big Aside: Changing how we release software

Scott Aside: It's also worth noting that while there is a bunch of stuff in the next version of Visual Studio, there's an equally compelling amount of stuff being released from the Azure/Web Team on NuGet. This gets to my LEGO analogy where we developers have more choice of what we snap together. Most importantly many things will only live on NuGet. I'm looking at the possibility of  NuGet Feed of Supported Microsoft Products. Folks sometimes assume that NuGet is a place to throw binaries up because it's convenient, but we also need a way to know if a NuGet package is actually a support product, kind of like "Verified" is on Twitter. I'm interested in your thoughts on this in the comments, or even better, in the Discussion Tab on the NuGet project site.

Shipping via NuGet is also significant because it helps level the playing field with Open Source libraries. Microsoft's open source libraries will "compete" for our developer-attention by all being in NuGet, and folks should use the ones that make them happy. If you want to use Microsoft's Ajax Minifier or any of a half dozen others, then just get the one you want from NuGet. Microsoft's won't ship out of the box. It'll be on NuGet.

Visual Studio 11 Developer Preview

A new Solution ExplorerTuesday the "Windows 8 Express" version of Visual Studio was released with the Windows 8 Developer Preview release which supports Windows 8 development. Wednesday during the keynote with Satya Nadella,  Scott Guthrie, Jason Zander  Visual Studio 11 Developer Preview and .NET 4.5 were announced. The bits are available today to the public.

ASP.NET 4.5 Developer Preview includes new core functionality like WebSockets, anti-XSS encoding, granular request validation. It also includes Web Forms improvements like model binding, support for HTML5 and unobtrusive JavaScript. And there have many performance improvements in ASP.NET when combined with Windows 8 Server can decrease startup time by 30% and reduce the memory footprint by 30%.

Scott Aside: I continue to put gentle pressure on all the teams about semantic versioning. In this case, .NET 4.5 is the right version number. It's using the .NET 4 CLR and is an additive (with bug fixes) release to .NET 4. Because it does that, it's very compatible. Your existing .NET 4 stuff won't (shouldn't) break. Check out the Target framework dropdown in this version of Visual Studio. See how you can target from 2.0 to 4.5 with the same IDE? That will be useful for corporate customers who need to develop 2.0 apps but still want the IDE improvements.
All the frameworks from 2 to 4.5 living together in a single dropdown. I never thought I'd see the day.

Visual Studio 11 Developer Preview includes new lots of new functionality including full editor support for CSS 3, full editor support for HTML 5, full editor support for JS, and many niceties like how Web Forms events can be wired up in source view, Web Forms designers can be launched directly from source view, how Live Inspector (code named "Eureka") makes editing the HTML of your document live much easier by automatically finding the HTML in your document as you select it in the Browser and much more.

Scott Aside: They've leveled the playing field across all the editors so things like regions, collapsing hierarchies, commenting, formatting, etc are all the same between CSS, JS, HTML and code. One more reason to just turn off all your foolbars and embrace the text editor and code.

You can read more about all the new features that are enabled in this release by reading the What's new in ASP.NET 4.5 and Visual Studio Web Developer whitepaper here: http://www.asp.net/vnext/whats-new.

NuGet 1.5 w/Dev11 Support Released

We just published an update to NuGet 1.5 that supports Visual Studio 11 Developer Preview. This allows developers on the Preview builds to continue to use NuGet with the preview releases of Visual Studio.

Note: NuGet does not support the "Windows 8 Express" release that was released yesterday. Support was just recently added to that SKU of Visual Studio and will appear in the next public preview release of "Windows 8 Express".

You can download the new release here: http://www.nuget.org/

ASP.NET 4.5

There's a lot of new improvements in ASP.NET and WebForms in particular in this coming release. ScottGu is doing a series and has done these posts already:

Model Binding will be familiar to MVC folks ,as is Routing. Both features now existing in both WebForms and MVC. So much time is spent in WebForms pulling data out of the request, via Forms, or QueryStrings, or Controls. Sometimes it seems like 30% of my WebForms code is just moving data from the Request into a variable. Now I can do this:

public IQueryable<Product> GetProducts(
[QueryString("q")]string keyword,
[Control("categories")]int? categoryId)
{
IQueryable<Product> query = _db.Products;

if (!String.IsNullOrWhiteSpace(keyword))
{
query = query.Where(p => p.ProductName.Contains(keyword));
}

if (categoryId.HasValue && categoryId > 0)
{
query = query.Where(p => p.CategoryID == categoryId);
}

return query;
}

This method supports a GridView that can sort, filter by category, and search via URL. Note the use of a nullable int as well. It makes WebForms code a lot cleaner, and it's just one example.

Scott Aside: ASP.NET 4.5 is additive to ASP.NET 4, so your existing apps will run, of course, but you can just start using these new features once you're using 4.5. I've been able to "refactor via subtraction" and yank out a bunch of tedious monkey code.

One other thing I wanted to say. It's becoming clearer to me that it's less about WebForms or MVC or WCF WebAPI Services or OData or IHttpHandlers or SingalR and more about ASP.NET. I used to call mix-and-match apps "hybrid" applications, but now I'm realizing they are just ASP.NET applications. I'll use whatever LEGO piece(s) I want and you should also.

MVC 4 and Web Pages 2 Developer Preview Released

The new responsive design of the MVC4 HTML5 default templateASP.NET MVC 4 Developer Preview is the latest release of our MVC framework. This release includes built-in support for mobile sites, new, fresh HTML5 project templates as well as jQuery Mobile. It has enhanced support for asynchronous methods, and custom code generation.

Also included are Web Pages 2 (like MVC with the V and C in the same file) a lightweight framework for creating dynamic, data-driven websites. The latest version expands support for mobile devices and for integrating client scripts, and adds helpers for tasks like mapping. You can download the new release for Visual Studio 2010 and Visual Studio 11 here: www.asp.net/mvc/mvc4

Scott Aside: Web Pages is what Rob and I used to make http://thisdeveloperslife.com and I'll be doing http://hanselminutes.com over again in Web Pages in the next week or so. If you love Razor just want a simple site, write code, hit F5, and deploy, WebMatrix and Web Pages is a nice change of pace. Also, the fact that they were able to integrate node.js into WebMatrix is not only cool but it brings up interesting questions about WebMatrix and what is can be used for. You can do PHP on it too, you know. Hm.

WCF 4.5 Developer preview AND "Web API" shipping out of band on .NET 4 and up!

Introduced Wednesday as part of .NET 4.5, includes new core WCF functionality like WebSockets, UDP multicast, improved streaming and better async support leveraging  Tasks and C# async improvements. We continued our commitment to simplicity with a number of configuration improvements (read "reductions"), making WCF throttles and quotas work for developers by default, better manageability. The WCF Client programming model is included in .NET Core profile available to Windows-tailored app developer.

Scott Aside: I've used WCF for years, begrudgingly. It is powerful, no one would disagree, but it's notoriously complex and scary. I'm impressed with what they've done in this release because they've effectively used the infinite configurability of WCF and pluged in a re-imagination of what WCF works like in a world of REST and JSON. When it's time for WS-* and the Enterprise, that part of WCF is still there, but when you move to the RESTful open web of 2011-2012, the new Web API is clean and light, nicely integrated with ASP.NET and able to create simple and lightweight web services using things like JSON and conventions that make sense.

RIA with HTML5/JavaScript

Dinesh announced the developer preview for RIA for JS/HTML5 in his BUILD talk. It's a set of jQuery plugins that let you easily work with server data on the client. By bridging the different tiers, RIA/JS lets you quickly build rich forms-over-data applications with HTML/JQuery. The libraries are available via RIAServices.jQuery NuGet package as well as codeplex. The WCF RIA Services for Silverlight were also updated via WCF RIA Services V1.0 SP2 and WCF RIA Services Toolkit Aug 2011 update.

Scott Aside: RIA was another project that I had checked out very early on and said, meh. I'm zero for two on judging their projects because the WCF team has embraced jQuery, JSON and a more open web in a big way. I'm impressed with their efforts and open attitude. Take a look at their "BigShelf" starter project and check out how they are using jQuery to retrieve and bind, filter and sort data on the client side. Again, fewer black boxes since it's all HTML and JavaScript. Be sure to scroll down on that page as it's a complete walkthrough.

Here's a rollup of other related links for you, Dear Reader, with downloads at the very bottom.

Announcement Links

Download Links

Enjoy!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

WebMatrix and node.js: The easiest way to get started with node on Windows

September 16, '11 Comments [24] Posted in IIS | nodejs | WebMatrix
Sponsored By

Tomasz Janczuk and Steve Sanderson are having entirely too much fun. I posted just two weeks ago on Installing and Running node.js applications within IIS on Windows - Are you mad? when Tomasz and the team got node.js running rather nicely under IIS. Now they've got a nice little development environment in WebMatrix.

Cats and Dogs, living together, mass hysteria

Then, Steve and Tomasz decide to share clever thing with us. Well, let me just show you. Remember, this is all in-progress goofing around v0.5 stuff at best but the concepts are sound.

node.js inside WebMatrix. You may start freaking out now.

And then:

Node.js Express Site1 - Microsoft WebMatrix (76)

Hit Run:

Node.js Express Site running on Windows

How can you use WebMatrix to develop node.js applications yourself? With these easy steps:

Isn't it lovely when LEGO pieces snap together so nicely?

Enjoy, Dear Reader.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Back to Basics: Big O notation issues with older .NET code and improving for loops with LINQ deferred execution

September 15, '11 Comments [58] Posted in Back to Basics | Learning .NET | LINQ
Sponsored By

Earlier today Brad Wilson and I were discussing a G+ post by Jostein KjĂžnigsen where he says, "see if you can spot the O(n^2) bug in this code."

public IEnumerable<Process> GetProcessesForSession(string processName, int sessionId)
{
var processes = Process.GetProcessByName(processName);
var filtered = from p in processes
where p.SessionId == sessionId
select p;
return filtered;
}

This is a pretty straightforward method that calls a .NET BCL (Base Class Library) method and filters the result with LINQ. Of course, when any function calls another one that you can't see inside (which is basically always) you've lost control. We have no idea what's going on in GetProcessesByName.

Let's look at the source to the .NET Framework method in Reflector. Our method calls Process.GetProcessesByName(string).

public static Process[] GetProcessesByName(string processName)
{
return GetProcessesByName(processName, ".");
}

Looks like this one is an overload that passes "." into the next method Process.GetProcessesByName(string, string) where the second parameter is the machineName.

This next one gets all the processes for a machine (in our case, the local machine) then spins through them doing a compare on each one in order to build a result array to return up the chain.

public static Process[] GetProcessesByName(string processName, string machineName)
{
if (processName == null)
{
processName = string.Empty;
}
Process[] processes = GetProcesses(machineName);
ArrayList list = new ArrayList();
for (int i = 0; i < processes.Length; i++)
{
if (string.Equals(processName, processes[i].ProcessName, StringComparison.OrdinalIgnoreCase))
{
list.Add(processes[i]);
}
}
Process[] array = new Process[list.Count];
list.CopyTo(array, 0);
return array;
}

if we look inside GetProcesses(string), it's another loop. This is getting close to where .NET calls Win32 and as these classes are internal there's not much I can do to fix this function other than totally rewrite the internal implementation. However, I think I've illustrated that we've got at least two loops here, and more likely three or four.

public static Process[] GetProcesses(string machineName)
{
bool isRemoteMachine = ProcessManager.IsRemoteMachine(machineName);
ProcessInfo[] processInfos = ProcessManager.GetProcessInfos(machineName);
Process[] processArray = new Process[processInfos.Length];
for (int i = 0; i < processInfos.Length; i++)
{
ProcessInfo processInfo = processInfos[i];
processArray[i] = new Process(machineName, isRemoteMachine, processInfo.processId, processInfo);
}
return processArray;
}

This code is really typical of .NET circa 2002-2003 (not to mention Java, C++ and Pascal). Functions return arrays of stuff and other functions higher up filter and sort.

When using this .NET API and for looping over the results several times, I'm going for(), for(), for() in a chain, like O(4n) here.

Note: To be clear, it can be argued that O(4n) is just O(n), cause it is. Adding a number like I am isn't part of the O notation. I'm just saying we want to avoid O(cn) situations where c is a large enough number to affect perf.

image

Sometimes you'll see nested for()s like this, so O(n^3) here where things get messy fast.

Squares inside squares inside squares representing nested fors

LINQ is more significant than people really realize, I think. When it first came out some folks said "is that all?" I think that's unfortunate. LINQ and the concept of "deferred execution" is just so powerful but I think a number of .NET programmers just haven't taken the time to get their heads around the concept.

Here's a simple example juxtaposing spinning through a list vs. using yield. The array version is doing all the work up front, while the yield version can calculate. Imagine a GetFibonacci() method. A yield version could calculate values "just in time" and yield them, while an array version would have to pre-calculate and pre-allocate.

public void Consumer()
{
foreach (int i in IntegersList()) {
Console.WriteLine(i.ToString());
}

foreach (int i in IntegersYield()) {
Console.WriteLine(i.ToString());
}
}

public IEnumerable<int> IntegersYield()
{
yield return 1;
yield return 2;
yield return 4;
yield return 8;
yield return 16;
yield return 16777216;
}

public IEnumerable<int> IntegersList()
{
return new int[] { 1, 2, 4, 8, 16, 16777216 };
}

Back to our GetProcess example. There's two issues at play here.

First, the underlying implementation where GetProcessesInfos eventually gets called is a bummer but it's that way because of how P/Invoke works and how the underlying Win32 API returns the data we need. It would certainly be nice if the underlying API was more granular. But that's less interesting to me than the larger meta-issue of a having (or in this case, not having) a LINQ-friendly API.

The second and more interesting issue (in my option) is the idea that the 2002-era .NET Base Class Library isn't really setup for LINQ-friendliness. None of the APIs return LINQ-friendly stuff or IEnumerable<anything> so that when you change together filters and filters of filters of arrays you end up with O(cn) issues as opposed to nice deferred LINQ chains.

When you find yourself returning arrays of arrays of arrays of other stuff while looping and filtering and sorting, you'll want to be aware of what's going on and consider that you might be looping inefficiently and it might be time for LINQ and deferred execution.

image

Here's a simple conversion attempt to change the first implementation from this classic "Array/List" style:

ArrayList list = new ArrayList();
for (int i = 0; i < processes.Length; i++)
{
if (string.Equals(processName, processes[i].ProcessName, StringComparison.OrdinalIgnoreCase))
{
list.Add(processes[i]);
}
}
Process[] array = new Process[list.Count];
list.CopyTo(array, 0);
return array;

To this more LINQy way. Note that returning from a LINQ query defers execution as LINQ is chainable. We want to assemble a chain of sorting and filtering operations and execute them ONCE rather than for()ing over many lists many times.

if (processName == null) { processName = string.Empty; }

Process[] processes = Process.GetProcesses(machineName); //stop here...can't go farther?

return from p in processes
where String.Equals(p.ProcessName, processName, StringComparison.OrdinalIgnoreCase)
select p; //the value of the LINQ expression being returned is an IEnumerable<Process> object that uses "yield return" under the hood
Here's the whole thing in a sample program.
static void Main(string[] args)
{
var myList = GetProcessesForSession("chrome.exe", 1);
}

public static IEnumerable<Process> GetProcessesForSession(string processName, int sessionID)
{
//var processes = Process.GetProcessesByName(processName);
var processes = HanselGetProcessesByName(processName); //my LINQy implementation
var filtered = from p in processes
where p.SessionId == sessionID
select p;
return filtered;
}

private static IEnumerable<Process> HanselGetProcessesByName(string processName)
{
return HanselGetProcessesByName(processName, ".");
}

private static IEnumerable<Process> HanselGetProcessesByName(string processName, string machineName)
{
if (processName == null)
{
processName = string.Empty;
}
Process[] processes = Process.GetProcesses(machineName); //can't refactor farther because of internals.

//"the value of the LINQ expression being returned is an IEnumerable<Process> object that uses "yield return" under the hood" (thanks Mehrdad!)

return from p in processes where String.Equals(p.ProcessName == processName, StringComparison.OrdinalIgnoreCase) select p;

/* the stuff above replaces the stuff below */
//ArrayList list = new ArrayList();
//for (int i = 0; i < processes.Length; i++)
//{
// if (string.Equals(processName, processes[i].ProcessName, StringComparison.OrdinalIgnoreCase))
// {
// list.Add(processes[i]);
// }
//}
//Process[] array = new Process[list.Count];
//list.CopyTo(array, 0);
//return array;
}

This is a really interesting topic to me and I'm interested in your opinion as well, Dear Reader. As parts of the .NET Framework are being extended to include support for asynchronous operations, I'm wondering if there are other places in the BCL that should be updated to be more LINQ friendly. Or, perhaps it's not an issue at all.

Your thoughts?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Guide to Installing and Booting Windows 8 Developer Preview off a VHD (Virtual Hard Disk)

September 14, '11 Comments [245] Posted in Tools | Win7 | Win8
Sponsored By

New Windows 8 Boot Manager?I've posted before about my intense love for Booting off a VHD (Virtual Hard Disk). It's lovely. Of course, once Hyper-V on the client happens, it will matter less, but for now, here I am, a guy with a perfectly good, working Windows 7 machine who wants to also run the Windows 8 Developer Preview.

I could do a few things to play with Windows 8. I could:

  • Try a virtualization solution, but it might not work, I may not have the drivers I need and it won't be as shiny as running "on the metal."
  • Sacrifice a machine I have lying around. I'll probably do that at some point, but I'd like to try it out on my actual hardware that I use all day long.
  • Swap out my C: drive and use my main machine. I don't have a tool-less case, and I'm also very lazy, so, um, ya.
  • Dual boot. Dual booting may feel ninja but it ALWAYS ends on tears. And sometimes blood.
  • Boot on real hardware from a Virtual Hard Disk.

Booting off a VHD is my current preferred solution for trying crazy stuff because the only speed hit I'll take is on the virtualized hard drive. Everything else is real hardware. I do this all the time with presentation VHDs and one-off daily builds of stuff.

Warranty

Of course, this is just some dude's blog. I puzzled this out and while booting to VHD is supported, messing with your boot manager - especially with Preview (that means, NOT RELEASE QUALITY) Software is a recipe for losing your job and a messy divorce. There's no warranty, express or implied. If you quake in fear from the following instructions, you need to STOP. It may be the case that you are actually a Non-Technical Friend and you don't realize it. Well, someone just told you. Please don't destroy your hard drive. I don't know you and I don't how how you got here. Stop calling. Jimmy no live here, you no call back!

Booting a Windows 8 VHD off a Windows 7 Primary System

These instructions come with the WORKS ON MY MACHINE seal of approvalWhew, now that's out of the way, let's void a few warranties, shall we?

Please note that there are a half dozen ways to do this. You can do it all from the command line using tools like ImageX, DISM, etc, or you can do a lot of it graphically with tools like BellaVista. This is just the way I did it. It's not gospel. I'm sure the folks in the comments will have much nicer ways. Take them all with a nice grain of sea salt. You can also SYSPREP the VHD directly from the ISO's WIM with IMAGEX if you know what that stuff means. It's a little subtle and requires you go get some tools. While my process  is a little baroque, it just needs the one ISO->USB tool.

Step 0 - Have a lot of Disk Space

I like to have a roomy VHD. You can make one that expands or you can make a fixed size. 40 gigs is usually enough, but I like 60 gigs as a nice round number, plus this is the Windows 8 Developer Preview with Developer Tools. If you don't have enough space when an expandable disk "bloats" itself to the fixed size on boot, it'll blue screen, so expandable or not, have the slack space.

Step 1 - Make a USB stick or DVD from the ISO

Go get the Windows 7 USB/DVD download tool and get yourself a USB stick that will hold at LEAST 10 gigs. I used a 16 gig one. Go through the process by pointing at the ISO you downloaded and then preparing your USB key. You can also use the resulting USB key to boot and install Windows 8 from your sacrificial hardware if you like.

Choose ISOChoose Media TypeInsert USB deviceCreating Bootable USB device

Step 2 - Make a Virtual Hard Drive

You can do this later in the process by pressing Shift-F10 while in the Setup Tool, but I like to prep things up front. You can do it from the Disk Management GUI or from DISKPART at the Administrator command line.

Be aware that your VHD needs to be on an internal drive or SATA drive. USB won't work as the drivers are initialized too late in the boot process.

Also, if your machine is BitLockered, your VHD needs to be on a non-BitLockered partition and you need to suspend BitLocker during this process. Also, know your recovery key because I don't know it.

2a. Start up an Administrator Console and run DISKPART. Execute the lines after DISKPART> below, changing them for your own system.

C:\Users\Scott\Desktop>diskpart

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: HEXPOWER7

DISKPART> create vdisk file=d:\VMs\Win8.vhd type=expandable maximum=60000

100 percent completed

DiskPart successfully created the virtual disk file.

DISKPART> select vdisk file=d:\VMs\Win8.vhd

DiskPart successfully selected the virtual disk file.

DISKPART> attach vdisk

100 percent completed

DiskPart successfully attached the virtual disk file.

DISKPART> create partition primary

DiskPart succeeded in creating the specified partition.

2b. OR do it from the Disk Management GUI:

Create and Attach Virtual Hard Disk

At this point, you've got a VHD that's empty, but ready to have Windows installed to it. The VHD and your system are NOT ready to be booted from. That will come in a minute.

Step 3 - Boot off the Windows 8 USB Key

Now, restart your computer with your new USB key plugged in and startup your BOOT MENU. The hotkey is usually F12 to bring it up. You want to boot off the Windows 8 USB key.

Side Note: Folks with Gigabyte Motherboards. These motherboards are notoriously hard to figure out a USB boot. You need to make sure that you USB key is only plugged into the board directly in the back. Then, don't use the Boot Menu, it never works. Instead, enter the BIOS with the DEL key and manually put your USB Key (it'll be detected by brand, so be prepared to recognize the string) at the top of the Hard Drive boot order.

Boot of your USB key

Step 4 - Attach the VHD while still inside SETUP

Pay attention here. Actually, hell, pay attention to the whole thing, it's subtle.

Start the SETUP process, click Install Not but DO NOT PICK A HARD DRIVE. As shown in this screenshot, instead hit SHIFT-F10 to get to a console. We want to attach our VHD and install to THAT instead.

Shift-F10 from within Windows 8 Setup

In the screenshot above I haven't touched anything, yet.

Below, I've run DISKPART and selected and attached the VHD with these now familiar commands:

DISKPART> select vdisk file=d:\VMs\Win8.vhd
DISKPART> attach vdisk

That will look like this screenshot.

DISKPART commands have been issued, but the drives aren't refreshed yet

Next, ALT-TAB back over to the list of disks and hit REFRESH. You'll see your VHD show up. Mine is the 60 gig one. That's the blank we are going to install to.

Now the 60 gig VHD is visible

Note that installation will warn you that this VHD can't be booted to. Yet. That's cool, go ahead and install to that empty VHD.

photo 4

At some point it'll ask you to restart the computer. The setup process isn't done yet, but go ahead and reboot and remove the USB key.

Your system should reboot and setup will continue, this time off the VHD.

NOTE: I had expected at this point to go and manually create a BCD entry using BCDEDIT.EXE from an Administrator command line as I did in my first post on booting to VHD but it seems that is all done for us now!

The Windows 8 Developer Preview build automatically noticed that I was trying to boot off a VHD and added a Windows Bootloader option and put the description in as "Windows Developer Preview," saving me a half dozen tedious steps. I was very pleasantly surprised! I'd like to hear if you had the same experiences, Dear Reader.

I could tell it was working because my C: drive is a totally silent SSD and my D: drive is spinning rust. When the setup continued I could totally hear the hard drive that holds the VHD spinning. The installation completed happily at this point with me having to manually create an entry with BCDEDIT.

I confirmed it with bcdedit.exe /v while running Windows 8 Developer Preview.

Setup completed, and I rebooted again to make sure I could get back into Windows 7.

In fact, I was shocked to find a completely new bootloader had come into play. I was literally open-mouthed staring at it. It's not text, it's graphical and friendly! It actually and literally "did the right thing." Awesome.

This seems to be the Windows 8 boot manager that you'll see if Windows 8 Developer Preview is the default. Otherwise you'll see the Windows 7 text-mode one first. Very cool. I hope it stays past the Developer Preview.

New Windows 8 Boot Manager?

Here's what you get if you click Other Options.

New Windows 8 Boot Manager?

That's it. To recap:

  1. Make an empty VHD
  2. Attach to the VHD just before installing Windows 8 Developer Preview
  3. Install to the VHD
  4. Rejoice

Hope this works for you, Dear Reader. I'm happily booting Windows 8 Developer Preview to VHD today.

One final disclaimer to be CRYSTAL CLEAR. I puzzled this process out with the same bits given out at http://dev.windows.com. I don't work for the Windows team and I don't know anyone over there. I have no idea if this will work in the future. I only know it worked on my home machine, tonight, once.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.