Its been a while since you posted this so I hope you or others finds this useful. I had the same issue with Mac OS X Snow Leopard running on VirtualBox and not being able to run a later version of Xcode than 3.1. My understanding is that running Mac OS as a VM does not not allow you to run the standard built-in upgrade utility to upgrade the OS.
The resolution that worked for me was documented here How to install Snow Leopard Hackintosh in Virtualbox.
The following method is hacky and has not been thoroughly tested in any way. Use these instructions at your OWN RISK.
First you will upgrade Mac OS Snow Leopard then you will install Xcode 4.2 The steps you'll need are the following:
- Take a snapshot of your Mac OS VM in case something goes arigh
- Search google for "10.6.7 combo update" (replacing version number with the one you need)
- Download the combo update from apple's official site and run
- Complete the install (DO NOT REBOOT)
- Google "10.6.7 legacy kernel" and download replacing version number with same version number as the combo update (the author of the article recommends finding kernel by nawcom)
- Install legacy kernel
- Reboot Mac OS and your upgrade should be complete
(Note: when I rebooted the spinning wheel that appears during bootup stopped after a min or two. I had to force restart the VM with VirtualBox and it appeared to have updated properly)
- Once in Snow Leopard click on the time/date in upper right hand corner and click "Date & Time Preferences"
- Uncheck "Set date and time automatically"
- Change the date to 01/01/2012 (this is because of an expired cert check that is checked during the install)
- Google "xcode_4.2_and_ios_5_sdk_for_snow_leopard.dmg", download, and install it
- Once installed you should now have a working copy of Xcode 4.2.