GAC Comparison Tool for multiple servers?
Does anyone know of a tool that would allow me to generate a report of the assemblies installed to the .NET GAC on all the servers in my web farm? (30-40 servers)
Or alternativel开发者_运维知识库y, does anyone have a pointer or a link on some way of accessing the information programmatically, via WMI, or remote registry query, or some other technology?
Thanks Kragen, for hinting that beneath the veneer of Explorer's GAC view, there existed files I could query with the System.IO namespace. Luckily I have network access to each server.
I just needed, for a single assembly, to query the versions that existed in the GAC on many servers. While far from a complete reporting application, this snippet served my purposes nicely:
private static void QueryServerGAC(string IP)
{
string rootPath = String.Format(@"\\{0}\C$\WINDOWS\Assembly", IP);
DirectoryInfo root = new DirectoryInfo(rootPath);
foreach (DirectoryInfo gacDir in root.GetDirectories("GAC*")) // GAC, GAC_32, GAC_MSIL
{
foreach (DirectoryInfo assemDir in gacDir.GetDirectories("MyAssemblyName"))
{
foreach (DirectoryInfo versionDir in assemDir.GetDirectories())
{
string assemVersion = versionDir.Name.Substring(0, versionDir.Name.IndexOf('_'));
foreach (FileInfo fi in versionDir.GetFiles("*.dll"))
{
FileVersionInfo vi = FileVersionInfo.GetVersionInfo(fi.FullName);
Console.WriteLine("{0}\t{1}\t{2}\t{3}", IP, fi.Name, assemVersion, vi.FileVersion);
}
}
}
}
}
This can be called once for each server IP of interest, and prints the IP, DLL Name, Assembly Version, and FileVersion to the console.
Feel free to take this code and modify for your own purposes.
You can disable the default GAC view to turn it into a normal explorer view in the registry, just set the following value to 1:
HKEY_LOCAL_MACHINE\Software\Microsoft\Fusion\
(Source http://sqlmusings.wordpress.com/2007/11/17/how-to-disable-gac-view/)
You can then just use some folder comparison tool, or just work out what assemblies are present from the folder names.
FYI - this just turns off the explorer view, however other points of interaction with the filesystem (e.g. the File object in C#, or the command prompt) already see this view, so there probably isnt any need to set this registry key on all of your servers.
精彩评论