views:

37

answers:

2

This is not an urgent need but more of a curiosity I have had in the back of my mind for awhile. For each .NET framework version installed on my machine I would like to list the installed apps that require it. With this in hand, I could know whether or not I could safely delete earlier framework versions without causing any programs to fail. Is there such a utility? I somewhat doubt it, so as a close second I will take suggestions for how to code this in C#.

Example output:

.NET 1.1 required by:
    ProgramX, ProgramY, ...
.NET 2.0 required by:
    ProgramA, ProgramB, ProgramC, ...
.NET 3.0 required by:
    ...
.NET 3.5 required by:
    ...
.NET 4.0 required by:
    ...
A: 

Since the application using .NET 1.1 can work on .NET 2.0, 3, 0, 3.5 and .NET 4.0 (and in general, application using lower .NET version can run on higher .NET version), your task probably doesn't have too much sense.

joekoyote
@joekoyote - i think that is not necessarily true. It makes perfect sense from a system admininstration perspective to want be able to know that if you were to downgrade from v4 to v3.5 or v.20 which apps would be affected and which wouldnt?
InSane
this is not true. .net 1.1 requires the 1.1 framework. 2.0/3.0/3.5 all base on the 2.0 framework, and 4.0 is something different as well.
Femaref
@Femaref sorry, but you are wrong. .NET 1.1 application will work on .NET 2.0 and later framework. joekoyote is right.
Eugene Mayevski 'EldoS Corp
@In Sane Backward compatibility of .NET is true, no matter necessarily or not. Also, it doesn't make *any* sense to downgrade and remove eg. .NET 4.0 Framework while keeping, for example, .NET 2.0 Framework.
Eugene Mayevski 'EldoS Corp
okay, I searched a bit and it seems you are right. mea culpa.
Femaref
".NET 1.1 application will work on .NET 2.0 and later framework" - not quite correct. Should by *Most* .NET 1.1 applications will work on .NET 2.0...
Joe
I'd say "vast majority of apps". The applications are bound to specific version of runtime not allowing to use later runtime either when they are badly written or when they work together with runtime (eg. the application that replaces gacutil). There's a tiny share of apps that stop working on later versions due to breaking changes in framework. These things do happen, but they are also quite rare and usually fixed by developers.
Eugene Mayevski 'EldoS Corp
"I'd say vast majority" - you're possibly right, but my point isn't to try to quantify this - I'm just pointing out that you need to test whether your app works in a different framework version.
Joe
A: 

Just some pointers to what's needed, I doubt you'll pursue this when you find out what it takes.

Starting point is writing code that enumerates all of the EXE and DLL files on your disk drives. For each file you find, you first have to check if it is indeed a managed program. Next, you need to lift the metadata version number from the COR header. It indicates what CLR version the executable was built against. Common values are 2.0.50727 for .NET 2.0, 3.0 and 3.5, 4.0.30319 for .NET 4.0, I don't know the numbers for .NET 1.x

Next you need to use Assembly.GetReferencedAssemblies() to find out what .NET assemblies it has a dependency on. You'll need to build your own index of assemblies that are present in 2.0, 3.0, 3.5 and its service packs. This lets you find out what specific version is needed.

Next you need to parse any .config file that might be present for an EXE and check for <requiredRuntime> and <supportedRuntime> elements. The latter attribute is the tricky one since it can appear more than once.

There are probably some things I overlooked, like publisher assemblies and bindingRedirects. Use the source code for ildasm.exe in SSCLI20 to get a crack at reading the metadata version number. The win for such a tool is small. With one terabyte drives selling for a hundred bucks today, the potential savings of such a tool are worth about 4 cents.

Hans Passant
For .NET 1.1 it's 1.1.4322
Eugene Mayevski 'EldoS Corp
Based on your great information, you are correct that I shall not pursue it further :-). My reason for asking, though, was not pecuniary, but rather a push towards having a tidy system with less detritus hanging around to clutter it. In fact, the larger drives get, the more I would like to get rid of the excess. Tilting at windmills...?
msorens