How does Visual Studio know the type of a project?

When you click on the “Create unit tests” or “Create private accessor” options in Visual Studio, it will give you a list of your unit-test projects to create it in. But how does it know which of your projects are unit-tests? Similarly, how does it know that a project is a setup project, or a console application?

The answer, it turns out, is actually very simple. In the project file (.csproj, or .vbproj), there will be an XML element called “ProjectTypeGuid“. Setting the value of that element to any one of the GUIDs found in this list will change it’s project type.

The value is a semi-colon separated list, so you can set multiple different project types on a single project.


Infinite series in .NET

Functional languages such as Haskell have a very cool concept of lazy expansion. Basically, Haskell will put off doing work until it knows that the result will absolutely, definitely be required. I admire Haskell for this, as it is the way I tend to work as well (although I suspect you don’t have to feed Haskell beer and pizza, and then wait until a marathon midnight coding session has been done).

This is very useful, as it allows you to easily do operations on infinite series in Haskell. For example, to get the first 20 even numbers, you’d do something like:

take 20 [2,4..]

Haskell is then smart enough to know that you want to take 20 results from the list of even numbers, with no limits on the length of the list. What’s cool is that it will not create the list items until they are requested, so you don’t need infinite amounts of storage for that list (I don’t think I have enough DIMM slots for infinite RAM…)

So how would you do something similar in .NET? Well, .NET provides the yield keyword. This is used to create and return the items in a list dynamically so, rather than creating a list then iterating through it, you create the current item only as and when it’s required.

Let’s look at the equivalent C# code (note that it’s a lot longer than Haskell!!)

        public static IEnumerable EvenIntegers(int count)
            int result = 0;
            while (count > 0)
                result += 2;
                yield return result;

        static void Main(string[] args)
            foreach (int i in EvenIntegers(20))

Note that I am never storing the full list of integers – I only ever have one in memory at a time. Obviously, with a list of 20 integers, this makes little difference, but if you want to print out all the integers to Int64.MaxValue, this could make a *huge* difference. Also, if you don’t know how many items you are using, it’s going to be a lot quicker, as you will only create the list items you are definitely using, not the ones you could possibly be using.

The opposite of Agile

For the last few months I have been working on a project for a Very Large Corporation. If you haven’t worked in a VLC then you won’t be aware that they are pretty much that development practices there are pretty much the antithesis of Agile practices. We use the Waterfall method for our development, and we tend to do the most complicated thing that may just about work. The particular example I have in mind is one that is plaguing me now.

About 2 years ago, when our web-site project started, a decision was made by some Enterprise Architects, sitting in their ivory towers, stroking their beards. They decided that every thing our web-site does, every process, will be….a separate web-site. All 200 processes. Every single one of them. All to placate the invisible god of Reusability. “Ok, so you have a couple more web-sites? That doesn’t sound so bad.”, I hear you suggest. “Oh my child,” I reply kindly, slowly shaking my head, “if only you knew…”.

So lets examine some of the implications. Currently we’ve got 50 of the 200 web-sites deployed, so I’ll be using that figure.


One of the first things you notice when launching our site is that it takes 10 seconds to render the page. Half of this is due to IE6’s appalling rendering engine, but a good 5 seconds is because the site is handling logging, and authentication, and caching, and various other initialisations for that session. So what happens as soon as they click a link? A new web-site is launched, and this process is repeated. The net effect is that the whole system is hair-tearingly slow.


It took over a month just to get the code into smoke-testing. Every tiny problem was exacerbated by the need to roll out a fix to 50 web-sites. If it takes 10 minutes to make a change and tests the web-site, then you will literally be spending your entire fucking day making that one change. Also, we had a huge number of “fit-n-finish” issues (broken web.configs, missing files from solutions, etc.) which can be partly attributed to the difficulty of keeping 50 related projects correct and in sync.


We’re using ASP.NET MVC on this project, which should be great, because MVC is super-awesome-good. However, since each process is a new site, and since a process typically consists of 1 or 2 web-pages, the MVC framework becomes rather redundant. We could have used classic ASP for all the practical difference it would have made.

I hate architects 😦

SysInternals: So great, for so many reasons.

SysInternals make the essential Windows toolkit, which proved so useful that Microsoft bought them out. I’m not going to go through the tools here, but suffice it to say that Process Monitor and Process Explorer have saved my bacon on many, many occasions, and their BSOD screen-saver is fun for pranks.

What I found out today is that the entire tools collection is available as a network-share! Just go to \\\Tools and you can copy them over! This makes it trivial to script getting them onto a new PC.

The Sims – more TV Life than Real Life

My wife is a huge fan of The Sims, and I have tried to get into it on several occasions but have always given up once I’ve maxed out a career. After all, I’ve “won” at that point, so why carry on? Yes, this is a very classic gamer mentality, and yes, Will Wright has sold about 37 trillion copies of the game and yes, etc., etc.

But it got me thinking about what it would take to get me to keep playing, and I think it should take a leaf out of another very successful game. A Will Wright game. One that has sold about 37 trillion copies – Sim City.

Once you had understood the game rules for Sim City, it wasn’t too difficult to build a super-large city that made you billions of spondoolicks (or whatever the Sim currency was called). However, what made the game playable after that point was that your city would randomly destroy itself, through earthquake, flood, nuclear meltdown (hmm, this blog is getting strangely topical), or alien invasion. Then you would have to desperately save your city from the effects of these Acts of God/aliens.

I think The Sims could implement this very easily – “Oh no, you have caught gonorrsyphillherpalaids, and must treat it with Paracetamoxyfrusebendroneomycin for some outrageous cost. Or your house burns down. Or you catch mad.

As well as these catastrophic effects, you should have crippling upkeep costs (mortgages, insurance, car maintenance, tax, etc.), just like in real-life, and your debt position should directly affect your mental health – see how quickly you can give your Sim bi-polar disorder, by buying him amazing stuff, then having him open the credit-card bill.

Finally, if you do somehow manage to make pots and pots of money, it would be great if the AI could be realistic enough that your children bump you off for their inheritances. Just like in real-life.

Is that a decanter in your pocket…?

I appreciate that there are such things as taste, and fashion, and that I’m rarely on the cutting-edge of either page (to mix a metaphor), but who would buy something like this?

Is that a decanter in your pocket?

That’s right, it’s a large cock-and-balls decanter. With racing stripes! I assume it appeals to the port-drinking, stilton-eating NASCAR crowd. Unfortunately, I suspect the Venn diagram for that cross-over looks a little something like this: