Category Archives: Visual Studio 2008

Leveraging Windows 7 Boot to VHD to Test Visual Studio 2010

The goal of this article is simple: a clean installation of Windows 7 that can be used to test new versions of Visual Studio 2010 until we reach RTM. Since a new beta drops every couple of months (and maybe even an interim release or two in between for those lucky enough to get access to it), I don’t want to have to repave the machine for each new release. Since Windows 7 has the ability to boot into a VHD, I thought this would be the perfect opportunity to try this functionality myself.

Getting Started

The first thing I did was slide the Windows 7 DVD into the drive and rebooted the machine. Once the setup window appeared, I pressed Shift+F1 to open a command prompt and created a new VHD by typing the commands shown below.

diskpart
create vdisk file="d:\vhds\w7base.vhd" type=expandable maximum=80000
select vdisk file="d:\vhds\w7base.vhd"
attach vdisk

Once this was finished, I switched back to the setup window and clicked Install Now. I chose the advanced install option, after which I selected my newly created partition as the installation target and formatted it so the installation could continue. While waiting for the setup process to complete (which included at least two reboots, both of which properly loaded into the VHD without any issues, so that’s cool), I started working on this blog post.

After the install completed, I wanted to make sure I didn’t get confused by the boot manager now having two “Windows 7″ options at started. So I quickly opened a command prompt (as Administrator), and typed:

bcdedit /set description "Windows 7 Baseline"

This will change the name of the boot manager entry for the current machine to “Windows 7 Baseline,” distinguishing it from the normal Windows 7 install. Once I’ve completed all the setup tasks, I’ll set the regular Windows 7 option to be the default when I’m not working with the beta software installations.

Next I ran Windows Update, along with installing the Microsoft Security Essentials to have a basic level of virus/malware protection.

I almost always need a database server to do any sort of distributed application testing, so I wanted to have a SQL Server 2008 available. However, I didn’t want to have it setup on each virtual disk. So I installed it to the base installation, along with a few other tools that I use often (and are not really updated regularly). I also decided that since Visual Studio 2010 and Visual Studio 2008 run nicely side-by-side that I would go ahead and install Visual Studio 2008 on the base image since I’ll most likely be working primarily with 2008 through the next year.

When you boot from a VHD, your regular Windows system drive is available as drive D. This is really useful since you can keep a single checkout of all your projects and work on them from different systems! On my regular Windows 7 install, I created a “Shared” folder off the root (OMG not a Library?). Within that folder I have a Home folder which I use for SVN checkouts, and I also configured SQL Server to use a directory under Shared for all the data storage. This will be handy for ensuring that data in the database is updated regardless of which system is using SQL – very cool.

Making a Difference

With the above steps behind us, we now have a machine with two Windows 7 installations on it. The first, a regular disk-based install, is our primary installation that we use for whatever. The second, a VHD-based install, is our clean Windows 7 with our minimum set of software installed on it. It’s this clean version that we want to keep “pristine” to avoid having to redo all the steps above with each new release of Visual Studio 2010.

A quick note, the size of the VHD after all the software is installed is about 20 gigabytes, which is pretty substantial considering that we now don’t need to copy this space for each branch of the baseline we create — a nice savings!

To create the differential image, I restarted the machine and selected my regular disk-based Windows 7 install. Once it was loaded, I opened up a command prompt and created a new VHD based off the existing one I just finished creating.

diskpart
create vdisk file="D:\vhds\w7-2008.vhd" parent="D:\vhds\w7base.vhd"
create vdisk file="D:\vhds\w7-2010.vhd" parent="D:\vhds\w7base.vhd"

Once the partition is created, create a boot entry for it using:

bcdedit /v (this displays the GUID we'll use next for our copy)
bcdedit /copy {3F2504E0-4F89-11D3-9A0C-0305E82C3301} /d "Windows 7 - 2008"
bcdedit /v (to get the GUID of our copy, which is also displayed after the copy command as well)
bcdedit /set {3F2504E1-4F89-11D3-9A0C-0305E82C3301} device vhd="[C:]\vhds\w7-2008.vhd"
bcdedit /set {3F2504E1-4F89-11D3-9A0C-0305E82C3301} osdevice vhd="[C:]\vhds\w7-2008.vhd"
bcdedit /v (to verify our work)
bcdedit /set {3F2504E2-4F89-11D3-9A0C-0305E82C3301} device vhd="[C:]\vhds\w7-2010.vhd"
bcdedit /set {3F2504E2-4F89-11D3-9A0C-0305E82C3301} osdevice vhd="[C:]\vhds\w7-2010.vhd"
bcdedit /v (again, to verify our work)
bcdedit /displayorder {current} {3F2504E1-4F89-11D3-9A0C-0305E82C3301} {3F2504E2-4F89-11D3-9A0C-0305E82C3301}

In this case, {3F2504E0-4F89-11D3-9A0C-0305E82C3301} is my original VHD-based install, {3F2504E1-4F89-11D3-9A0C-0305E82C3301} is my copy for Visual Studio 2008, and {3F2504E2-4F89-11D3-9A0C-0305E82C3301} is my copy for Visual Studio 2010.

I now have three boot options when the system starts, my disk-based Windows 7 install, and my two newly created “differential” installs — one for Visual Studio 2008 and one for Visual Studio 2010. Since both of these are based off the VHD we created above, we want to make sure we don’t accidentally boot into the w7base VHD and change it — that would be like crossing the streams in Ghostbusters (read: bad). The /displayorder command takes care of this by having a side effect of removing the Windows 7 Baseline option from the list of boot configurations.

One thing to keep in mind, and another benefit of having the physical disk drive available as drive D, is that I do all of my work on the D drive (in the Shared folder). Since this drive is persistent I can be sure that I don’t lose my files as I boot between different installations of Windows 7. It also makes it so I don’t have to checkout projects on each VHD, which would waste valuable space.

Cleaning Up

So now that we have a nice baseline and a couple of working boot options (both of which don’t impact each other as changes are made), we can install our latest BETA/CTP/whatever on our 2010 install. When an update is released (in the form of a subsequent CTP, beta, etc.), we can take a few simple steps to revert our 2010 to a clean install.

First, we need to boot into our disk-based installation of Windows 7. Once there, there are a couple of options available. We could create an entirely new configuration by repeating the steps above. This would be helpful if we were in the middle of something on a current version of 2010 and wanted to try it in the update to check for breaking changes. The more likely option, however, is to just replace the installation with a clean baseline to install fresh.

To install fresh, we can just delete the existing w7-2010.vhd and create it again using:

diskpart
create vdisk file="D:\vhds\v7-2010.vhd" parent="D:\vhds\w7base.vhd"

The boot configuration is still pointing to that file, so it will find it after a restart and you can install the latest update without fear of some bad configuration/files from a previous beta/CTP getting in the way.

Conclusion

The new boot to VHD features of Windows 7 (which also work just fine for Windows 2008 Server R2 by the way) are a really slick addition to the Windows platform. Being able to take advantage of the VHD features, differential disks in particular, really makes it a great host for the various incarnations of Visual Studio. I hope this guide has helped ease some of the CTP/BETA pain that comes with running on the bleeding edge.

MassTransit 0.4 Released

I’m happy to say that we’ve just tied a bow around the latest release of MassTransit. Release 0.4 includes a number of new features and some tweaks to the internals as well. I’m going to describe a few of those features below, but you can grab the latest from the trunk or download the 0.4 release.

Building MassTransit

Since Visual Studio 2008 has been out for almost a year, it is now required to open the updated solution for MassTransit. In the main folder, the MassTransit-2008.sln is the one to use to build and run the unit tests. Many of the samples solutions are also 2008 solutions. The assemblies, however, are still targeting the .NET 2.0 framework, making them usable on both 2005 and 2008 projects. With only the .NET 3.5 framework installed, you should be able to run the build.bat to build the project without Visual Studio (our CI server does this).

Timeout Service

To enable automated support for timeouts in sagas, a new timeout service is available. This is a general service that can be used to schedule timeouts for whatever purpose may be needed. To schedule a timeout, the application should publish a ScheduleTimeout message with the duration or time when a response should be sent. The application/service can then consume the TimeoutExpired message, which will be published by the timeout service when the timeout period expires.

Message Deferral Service

One of the scenarios I often find in our systems is the need to poll a remote resource to determine if an operation has completed. To support this behavior without custom code in each instance, a new message deferral service has been added. This can be used to defer the delivery of a message until a period of time expires. The deferral services leverages the timeout service for scheduling and we republish a message after that timeout expires.

For example, we have a CheckRemoteResponseStatus message in one of our systems. This is initially published after a request is submitted to a remote system and a remote transaction id is returned. The first time the consumer gets the message, it checks the remote system for a response. In most cases, the response is immediately available and the saga continues. However, sometimes the remote system is too busy to respond and returns a pending status. In this case, the same CheckRemoteResponseStatus message is published within a DeferMessage. The deferred message service handles that message and will republish the original CheckRemoteResponseStatus message when the timeout expires. The saga will then handle the message to see if a response is now available. The saga keeps track of how many times the remote status has been checked and uses a sliding interval that increases as the retry count increases. Eventually, the final retry results in a failed transaction and is handle appropriately.

The nice thing about this is there was no custom retry logic required, and a common timeout and message deferral service were used. There are likely other cases within the application that will benefit from this shared functionality.

Transactional Queue Support

With 0.4, the entire method of reading from the endpoints has been redesigned. Previously, a single receive thread was used to receive from the endpoint which then dispatched the message handling to the dispatcher inside the service bus. This has been redesigned to use the dispatcher threads to perform the actual receive from the endpoint, using a transaction (ala System.Transactions) to handle the message reception. This keeps the transaction to a single thread while at the same time allowing concurrent message reception.

The transaction carries over into actions that are part of the message consumer. If a database update is part of the consumer, that database update can cause the entire message to rollback if it fails. If any exception is thrown, the entire reception of the message, any additional database operations, new messages sent, etc. will all be rolled back with the transaction.

Performance Improvements

Dru spent some time in NYC with Ayende Rahien reviewing the MT source code and Oren recommended changing from using locks to ReaderWriterLocks to improve concurrency. The changes in the threading system, along with the elimination of a lot of locking in favor of reader/writer locks has nearly doubled the throughput of messages when using a multi-core system using MSMQ. There have been a number of other internal tweaks as well to improve the concurrency of the bus dispatcher.

Control Bus

To enable competing consumer in a publish/subscribe environment, the control messages need to be on a separate bus from the data messages. To allow multiple services to compete against a single data channel (single MSMQ) in order to load balance and handle failure scenarios, the services cannot compete on the control messages such as subscriptions. The subscription client has been tweaked to allow it to operate on a separate bus from the data bus, at the same time notifying the subscription service of messages handled by the local endpoints of the service.

It’s easy to setup a single service that consumes messages from multiple buses (which in turn each have a specific endpoint being serviced). When a component is created to consume a message, the specific bus/endpoint that received the message is injected into the component (via setter injection) so that any subsequent messages can be published to the appropriate bus.

Health Service

The health service has been added making it easy to monitor endpoints and identify when an endpoint goes down. Periodic heartbeats are sent to the service and when a heartbeat hasn’t been received in a while, it marks that endpoint as down and attempts to directly ping it to get a response. The heartbeats can be subscribed, so a monitoring tool can keep track of which endpoints are there and what they are handling.

Configuration Model

To make it easier to use the bus in different containers, a new configuration model has been added to build and configure a service bus instance. This will ultimately result in moving a lot of the code used by build a service bus out of the container-specific facilities (such as the Windsor container).

Host Improvements

The ability to create and deploy Windows services has gotten easier with the updates to the Host assembly in MassTransit. With only a few files to define the lifecycle of a service, it is easy to get the ability to run, test, install and deploy a service. This includes services that are using the service bus. There is little to no coupling between the host and service bus, making it usable for a variety of purposes.

Learning MassTransit

A lot of requests have come for information on how to learn to use MassTransit. During Tulsa TechFest this week, we’re going to record our presentation and make it available online within a few days. This should give at least some introduction on how to use MassTransit (the presentation is mainly on distributed architecture, but we’re using MT for the demo bits). We’re also talking about doing a couple of podcasts on how to use it as well. Depending upon how that goes, we’ll try to do a couple of screencasts on “creating your first project with MT.”

The best way to discover how to use the code is to review the samples. The WinFormSample gives an overall example of how a variety of features are used. The HeavyLoad shows how many of the pieces work as well. The samples folder has a few others that demonstrate how to use MT in other scenarios.

So, check out the new release and give us some feedback on how the new features are working. We’ve already got a few backlog items that we’re slating for 0.5 based on some other contexts that have come up in our applications. Feel free to post on the message group or send either Dru or I an e-mail or tweet if you have any questions.

Visual Studio 2008 InstallFest in Tulsa

Tonight was the Tulsa installment of the Visual Studio 2008 InstallFest that is sweeping the cities this month. In a move to get people excited about VS2008, Microsoft handed out 150 trial copies of VS2008 to those that registered. As an encouragement to those that installed VS two-double-oght-eight on site, participants who demonstrated the post-install goodness were given a t-shirt to commemorate the event.

This was by far the biggest turn out we’ve had outside of Tulsa TechFest at OSU Tulsa. Tons of food and drink were provided, including Mazzio’s Pizza, Domino’s Pizza, and Spaghetti Warehouse pasta trays. There was plenty to go around and everyone was talking and discussing anything and everything. Good times.

Once we arrived, we camped out and provided the entertainment for the room. Chris Koenig provided several XBOX 360′s for the event, one with Guitar Hero III and another with my new favorite game Rock Band. Rock Band absolutely kicks ass. We had 3-4 players all the time, and I even uploaded a few videos of people playing the game. The multiplayer on Rock Band makes the battle mode on GH3 look lame. Having a group playing all parts of the song is more fun than you could imagine based on the videos on the web.

These videos were shot on my MacBook Pro and uploaded at the event using iMovie’s YouTube export:

Needless to say, I’ll likely be getting an XBOX 360 and Rock Band sometime in the near future!