Monthly Archives: April 2011

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.0\Common7\Tools\
VS80COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\Tools\
VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\

or we can get it from the registry the installation directory which is located on HKLM\SOFTWARE\Microsoft\VisualStudio\<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 HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\<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}Microsoft\VisualStudio\{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

Console.WriteLine(VisualStudioHelper.GetVisualStudioInstallationDir(VisualStudioVersion.VS2010));

Console.WriteLine(VisualStudioHelper.GetVisualStudioInstallationDir(VisualStudioVersion.VS2008));

Console.WriteLine(VisualStudioHelper.GetVisualStudioInstallationDir(VisualStudioVersion.VS2005));

Console.WriteLine(VisualStudioHelper.GetVisualStudioInstallationDir(VisualStudioVersion.VSNet2003));

Will result in

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\

C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\

 

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 2010\Tools)

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).

tfspe-1tfspe-2

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.

OData Service for Team Foundation Server 2010: Beta now available

 

Microsoft has released a beta version of an OData service for TFS 2010. This is great way for people wanting to get data from TFS without having to use the object model.

[Update: If you are having problems installing this, there is a know issue. More details and workaround on Brian Keller's Post]

Besides exposing all TFS capabilities via Web Services, TFS provided from day one an object model SDK that allows you to interact and extend TFS capabilities (incidentally this is the same object model Microsoft uses to write Team Explorer, so Microsoft  can’t do on its own client  anything that you  can’t do yourself). The object model is the recommended way to interact with TFS, since not only provides a good abstraction over the web services but it also isolates you from changes made to the web services from release to release.

But this meant that in order to interact with TFS you had to use .NET (or any language capable of talking to .Net) in your applications. With the new OData service you can now get data from TFS from any other client that can talk OData.

This opens up great possibilities, like writing clients in WP7, Android,tables, Linux, Mac, Web Servers or for example showing up data in Sharepoint with no programming at all (basically any client that can speak HTTP)

For non programmers this also opens a tremendous opportunity for exploring data since you now use Power Pivot in Excel to get data from TFS and correlate them with other sources quite easily.

Here you can see a (small) list of consumers that are able to consume OData.

You can read more details about the OData Services on this Brian Keller Post which explains this more better than me.

For those to lazy to follow the click I’ve embedded the video (Silverlight) right here Smile you can also download the video to your Zune, Ipod, WP7,etc here

Improving Visual Studio source offline support with TFS

 

When TFS 2005 was released there was no offline support, if you went somewhere to which you had no connection to TFS you couldn’t be considered an happy camper.

After a few months, Microsoft released a version of the Power Tool that had the ability to work offline. But it was a very manual process. You had to remove the read only attribute of a file and when you got your connectivity back, you would invoke the (command line) Power Tool command so changes could be reconciled (files without the read only attribute would be checked out, new files would be added, etc.).

With the 2008 release things got a little better. Offline support was added.  If you opened a solution which was binded to TFS source control and you didn’t had network access to TFS Visual Studio would be asked if you wanted to work offline. (Most) changes would be recorded and when you went online changes would be reconciled (much like the power tool capability but integrated with VS and the GUI).

It wasn’t much better than 2005, but it was surely an improvement. However a feature was still missing. You couldn’t go offline when you wanted. You could only go offline when the solution was opened. So if you disconnected from the network and wanted to work offline you had to close and reopen the solution (which can take some time on large solutions).

TFS 2010 didn’t provide any love to the offline support and things are the same as in 2008.

If you miss the ability to go offline without closing/reopening the solution you can go to Visual Studio Gallery and install GoOffline Extension

The action is available at Files->Source Control to go online again, just use the use go online button available on Visual Studio

image

Organizing your build definitions in folders

 

As most people know from experience Team Projects who have a lot of build definitions are hard to navigate. The list of builds is endless and presented in a flat view.

Something that would a lot on these cases would be a search/filter and a way to organize your build definitions in an hierchical mode.

The community has been asking Microsoft for this for a long time. Since 2010 didn’t introduced this feature, fellow ALM MVP Terje Sandstrom as taken matters into his own hands and developed a Team Explorer addin that allows you to organize you build definitions in a tree.

image

You can download a copy of this Team Explorer extension here

Visual Studio and TFS Books

 

I’m asked fairly frequently which books I recommend about Visual Studio or TFS, so I decided to write some words about it to see if I get this asked less frequently.

Before Visual Studio 2010 there were not a great number of books that I (could) recommend. If a person wanted to have a light yet complete view out TFS was all about then I would recommend Richard Hundhausen introductory book Working with Microsoft Visual Studio 2005 Team System (Pro-Developer) (this was the first I ever read about Team System (I’ve read the edition it was still targeting Team System Beta and was still called Introducing Visual Studio 2005 Team System Beta Edition (Pro-Developer)))

tfs1

If you wanted a general book on TFS that covered the entire platform and with a great level of detail then I would recommend THE book Professional Team Foundation Server . A book which was not only very complete, but it also had a lot of gory details on how to do things on TFS that you couldn’t find anywhere else (for a long time).

if you wanted to learn how to do some project management with TFS then the book to recommend was  Managing Projects with Microsoft Visual Studio Team System.

There was also a book that I would somehow recommend  Global Outsourcing with Microsoft Visual Studio 2005 Team System (the title is somehow misguiding) the book isn’t great, but I would recommend it since it contained some code samples from which I’ve learned a few tricks (this was in a time the documentation for TFS object model was pretty scarce).

And that was it. There were some more books but I can’t remember any that I would recommend (either I’m being unfair because my memory is foggy or I can’t remember any because there wasn’t anything else to me memorable enough so I have a recollection that I would recommend it Smile).

For the 2010 release, things have changed. There are a lot of great books, and there a bunch a of them that I would recommend without hesitation.

If you want a generic book, that covers the entire Visual Studio ALM stack, then the book to get is Professional Application Lifecycle Management with Visual Studio 2010. It is a great book that covers the entire Visual ALM family from toe to toe. This is an amazing book that has been able to cover in more than 600 pages, every major area and feature of Visual Studio. Both the IDE (including features from all SKUs) and the server (TFS including lab management). Highly recommended.

Disclosure: I have two copies of this book. One that I bought and another that has been sent to me by the Publisher so I could review it.

If build automation is your kind of thing, then THE book about builds is Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build. It is a great book on MSBuild and building with TFS. The second edition has been greatly enhanced with information about Team Build 2010 and has a bonus it has a nice chapter on MSDeploy to be used in conjunction with Team Build (or independently)

Disclosure: I have written a small commentary that has been included in the book based on a review that I did before the book was published

If you are interested in learning more about testing with Visual Studio, then no list  of books would be complete with referencing Software Testing with Visual Studio 2010. The intended audience of this book is not developers but people who primarily test software (traditionally there has been a great gap between testers and developers. A gap that Visual Studio team is working hard to reduce). I still haven’t finished reading the book, so I can give you my full impression about it. But from what I’ve it is a great book, although it could have gone a little deeper and provide more details on some topics. Overall it is a great book

Last but not the least is Professional Team Foundation Server 2010. I can’t give you a first hand opinion on this one because my copy hasn’t arrived yet. This book focus solely on TFS, although I haven’t read it yet I can recommend it without even reading it since I personally know all the authors but one and I’m pretty confident in recommend it since they are unable to produce something that isn’t great.

In summary (in no particular order)

 

tfs2tfs5tfs3tfs6

I’m sure there are other books out there that are equally good, but I’m not aware of them (yet. Smile)