开发者

Get list of programs using each .NET version installed on my machine

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜