Getting Visual Studio installation directory



Determining the installation path of Visual Studio is something that sometimes is needed. For example we may we need to interact with Visual Studio executable (for example to reset visual studio or registering something on an installer).

But how can we determine where Visual Studio is installed? There are basically two ways of doing it.

  • Getting it from the environment variables.
  • Reading it from the registry

The path is stored in an environment variable called VS<internal version number>COMNTOOLS where <internal version number> is the visual studio internal version number (multiplied by 100). This is not exactly the installation path but we can infer from it.

On my machine I have the following environment variables

VS100COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 10.0Common7Tools
VS80COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 8Common7Tools
VS90COMNTOOLS=C:Program Files (x86)Microsoft Visual Studio 9.0Common7Tools

or we can get it from the registry the installation directory which is located on HKLMSOFTWAREMicrosoftVisualStudio<InternalVersionNumber>InstallDir

This is true for 32 bit systems.

On 64 bit systems things are a little bit different. Since Visual Studio doesn’t directly support 64 bit systems, on 64 bit systems VS runs under the Windows on Windows system ( WoW64 ) so we must also that into account on 64 bit systems

in 64 bit systems HKLMSOFTWAREWow6432NodeMicrosoftVisualStudio<InternalVersionNumber>InstallDir

But this only applies on 64 bit processes, if you are running under a 64 bit system but with a 32 bit process you don’t need to get the WoW registry key since windows transparently redirects registry accesses on that case (you can read more about redirection here).

If you follow these rules, you will be fine, but even better then a detailed description would be some running code Smile

This little enumerate allows you to define the several versions in a more friendly way

/// <summary>
/// Represents the several visual studio versions.
/// Internally the value is stored as the VS internal number multiplied by 10 (eg: VS2010 is 100 since it's internal version number is 10.0)
/// </summary>
public enum VisualStudioVersion  { VS2010 = 100, VS2008 = 90 , VS2005 = 80, VSNet2003 = 71, VSNet2002 = 70, Other = 0};

And this code allows us to get the installation directory for the several VS versions

using System;
using Microsoft.Win32;
using System.Globalization;


/// <summary> /// Gets the installation path of a given VS version. /// /// Supported versions 2005, 2008 and 2010, .Net 2003 and .Net 2002 /// </summary> internal static class VisualStudioHelper { /// <summary> /// Gets the installation directory of a given Visual Studio Version /// </summary> /// <param name="version">Visual Studio Version</param> /// <returns>Null if not installed the installation directory otherwise</returns> internal static string GetVisualStudioInstallationDir(VisualStudioVersion version) { string registryKeyString = String.Format(@"SOFTWARE{0}MicrosoftVisualStudio{1}", Environment.Is64BitProcess ? @"Wow6432Node" : "", GetVersionNumber(version)); using (RegistryKey localMachineKey = Registry.LocalMachine.OpenSubKey(registryKeyString)) { return localMachineKey.GetValue("InstallDir") as string; } } /// <summary> /// Gets the version number as used by Visual Studio to identify it's version internally. /// /// eg: Visual Studio 2010 is 10.0 and Visual Studio 2008 is 9.0 /// </summary> /// <param name="version">Visual Studio Version</param> /// <returns>A string with the VS internal number version</returns> private static string GetVersionNumber(VisualStudioVersion version) { if (version == VisualStudioVersion.Other) throw new Exception("Not supported version"); return ((int)version / 10).ToString("{0:0.0}", CultureInfo.InvariantCulture); } }

Executing the following code on a 64 bit operating system





Will result in

C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDE

C:Program Files (x86)Microsoft Visual Studio 9.0Common7IDE

C:Program Files (x86)Microsoft Visual Studio 8Common7IDE


Yes I have all these versions running on my machine (I’ve used to have also VS .NET 2003 but on the last repave I didn’t reinstall it Smile)

Note: This code requires either .Net 3.5 or higher  since it uses  Environment.Is64BitProcess which is only been made available since .Net 3.5 if you want to run this with fwk 2.0 you will need to determine if we are running on a 64 bit process using another method.

Visual Studio internal version numbers are

Visual Studio 2010 10.0
Visual Studio 2008 9.0
Visual Studio 2005 8.0
Visual Studio .Net 2003 7.1
Visual Studio .Net 2002 7.0

Is this useful for something? Perhaps or perhaps not. But that is a history for another post Smile


Controlling Lab Management VM Placement Policy



Lab Management is part of Visual Studio 2010 and it’s a great way to virtualize your test laboratory. In a simplistic way, we can say it allows you to test your applications without having to have a multitude of physical machines and different installations (multiple OS versions, multiple languages, multiple browsers. Whatever matrix of configurations you have to test your applications in).

It does this by allowing your to virtualize your environments in an easy way. Specially it allows your testers to easily launch virtualized test environments without having to have knowledge of virtualization (not only launch but also self provision), your lab administrators to easily provisions new environments based on VM templates. It also reduces the gap between developers and testers since when tests are being executed data can be automatically recorded (Intellitrace, video, event log events,etc,etc) and attached to a bug for easier reproduction of issues.

It also fully integrates the testing activities into your development practices, since it is very easy to automatically deploy an application into a fresh VM from your build process or even run automated functional UI tests automatically.

By I digress, today I merely wanted to show you a little “trick” for configuring your lab management to allow you to deploy more machines then your hyper-V can theoretically hold.

Lab managements deploys your virtual machines into the hosts that you have configured on your System Center Virtual Machine Manager (SCVMM), in fact it can also support multiple hosts and multiple group of hosts.

When you are provisioning environments on your lab, after defining the VM(s) that compose your environment (you can have as many environments as you want. An environment represents a set of machines eg: Web Server, Database Server,…) you have to deploy them before it can be used.

The act of deploying a environment means lab management is going to provision the environment by creating the actual VMs on a host (or more).

When you deploy an environment, lab management scorches your Hyper-V hosts (in the group) to see which one has enough resources to host your VMs. It can deploy your environment across more than one host (unless your require network isolation which mandates that the entire environment needs to be hosted on a single host).

The VMs needs two kind of resources. Memory and Disk. In order to deploy an environment you need an host that has sufficient memory and sufficient disk space. Disk space is easy to figure it out, but what does mean mean sufficient memory?

By default sufficient memory means: The memory the machine has minus the memory reserved for the virtual machines already deployed (either they are running or not) is bigger than the memory for all VMs of the environment being deployed.

This means that if you have environments which are rarely running they are accounted for and this can prevent you to deploy new environments even if your machine has enough resources to run a given environment,

This is called the Conservative Placement Policy and it basically assumes that all your deployed environments need to be running all the time (so in order to have more environments you may need to free up space by removing environments)

If on the other hand you want to have multiple environments and you don’t need to be running all of them at the same time and you can afford to stop/start them when you need them, it is perfectly fine if you over allocate the required VM over your physical resources (or you are using Hyper-V SP1 Dynamic memory feature). Lab management supports a policy that only considers memory occupied by running VMs at deployment time.

This would mean you want to have an aggressive placement policy.

By default lab management is configured in Conservative mode (on a host group by host group basis)

You can configure the placement policy on a host group by using tfsconfig.exe lab command (located on %programfiles%Microsoft Team Foundation Server 2010Tools)

For example:

TfsConfig.exe lab /hostgroup /CollectionName:<CollectionName> /Edit /Name:<HostGroupName> /LabEnvironmentPlacementPolicy<policy>

Possible values for policy: Aggressive or Conservative

You can easily spot an host group configured with conservative policy when you try to deploy an environment and are presented with the error:

Memory requirement of the virtual machine(s) exceeds the available host resources. The placement policy for this host group is set to be conservative and hence virtual machines that are in stopped state are also accounted as consuming host resources.

TFS Phone Explorer. Another TFS client for WP7



When only I few days ago I wrote TFS and Windows Phone 7 I was far from guessing that only a few days later I would be writing again about this topic. So this should be probably title TFS and Windows Phone 7 II, but I don’t want to take a chance of writing a third series so I’m not using another title. Smile

Black Marble just released on WP7 Marketplace TFS Phone Explorer.

The name is a bit misleading (probably because they may have greater plans for future versions Smile).

For now it’s mainly a build monitor, it allows you to see the builds on your server. Given a build you can do two things. Queue another build (great feature) and see the detail of a build (this opens a full chest of options). You can see detailed information about the build (time taken, the person who queued,etc,etc) the (number) of tests (passed, failed and inconclusive), the compilation status (errors and warnings), the work items that have been associated with the build. Unfortunately the associated changesets are not available (perhaps this will be an incentive for people to use the best practice of associating work items with checkins Smile).

You can also see a work item detail and make changes to it (not all fields are shown and I’m still trying to understand how the app chooses the fields to be displayed)

You can also create work items, which can be a great feature if you are on the road and remembers something that needs to be entered as a workitem (it has happened to me and had to write it down on onenote since I have a terribly memory Smile).

In order to use this application on your own TFS you need to install a service (available from Black Marble)

I think this is a great V1 that has room for improvement. Specially if capability to see work items and changesets.

Something that I miss on this application (and TFS Monitor) is the lack of filtering, on a big TPC you can get be information overload pretty fast. But I’ve found this to be a common issue with WP7 apps since the Metro (I could be wrong since I haven’t read the spec <g>) UI doesn’t seem to have a way to filter information (other than using panorama for it).



TFS and Windows Phone 7



A long time time I entered on my backlog the user stories for a WP7 application to get data from TFS, when Microsoft release the beta for OData Service for TFS I reckoned I could dispose those entries on my backlog since it was merely a question of time someone wrote a WP7 client for TFS that would allow to easily visualize data stored on TFS.

I was not very far from the truth, yesterday I was browsing WP7 marketplace and found TFS Monitor that allows you to see data from TFS. It supports viewing builds, work items, team projects and also allows to see events (apparently work item changes, check ins and failed builds).

I’m still not totally sure but I think it also supports live tile notifications.

It comes pre configured with a demo server on the company site, it doesn’t has any instructions of how you can connect to your own server (the settings allows you to configure your server URL and auth parameters) however it doesn’t say if you need to install anything on the server.

I haven’t investigated that part yet, but from what I’ve seen (the first version threw some exceptions Smile) it seems you just need to install OData Services for TFS and configure TFS Monitor to use that URL.

The application is available on the Marketplace for free.

I’ve done some digging and found a presentation from one of it’s authors on slideshare.


Getting updated info on TFS and Visual Studio with little effort



There are dozens and dozens of high quality blogs on TFS and Visual Studio that helps up not only keep up with the latest information but also have a huge amount of high quality information that allows us to make a better use of TFS and Visual Studio.

Unfortunately the day only has 24 hour and people are typically so busy that the available bandwidth to keep up with the deluge of information that is thrown at us every day is very low.

If this is your case I would recommend that you follow three blogs. The first one is quite obvious since it’s probably the _authoritative_ source of information on TFS. The posts are not very frequent but when he posts they have a high informational value. Either explaining Microsoft vision on some TFS topic or on important things that are released or coming in the near future.

if you haven’t guessed by now, I’m talking about Brian Harry’s blog.

The other two links, are two high frequent highly condensed information with pointers to interesting posts that are written on several blogs. These two guys scorch the web for high interest posts and give you a list of posts around the wed. These two blogs are a great way of having a good digest of what is happening on TFS and Visual Studio with very little effort on your part.

I’m talking about the venerable Mickey Gousset and his Team System Rocks which has been regularly writing VSTS Links series for as long as I can remember.

The other is Visual Studio and TFS Daily in which Trenton Nix write daily uptakes on posts that he considers interesting.

If you have little time and yet feel the need to keep an eye on what it’s interesting these would be the resources I would recommend for you to follow and will allow you to keep up with very little effort.