Friday, November 2, 2007

Querying the .Net CF GAC programmatically - ListGACTool sample app

If you want to get a list of the assemblies installed on the .Net CF GAC programmatically, you can inspect the device registry accessing the following path:

[HKEY_LOCAL_MACHINE\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global]

You'll find there one string value for each assembly registered on the GAC. The name is the assembly full name and the value is the GAC file path.

I'm including here a sample app which you can use to list your GAC in PocketPC. Please pay special attention to the method:

private void updateGacList()
{
gacList.Items.Clear();
RegistryKey gacKey = Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global");
foreach (string valueName in gacKey.GetValueNames())
{
if (valueName.IndexOf(filterTextbox.Text) == 0)
gacList.Items.Add(valueName);
}
}

Here you have a screenshot. As you can see, the app supports assembly name filtering and it's just for learning purposes.

ListGacToolScreenshot

You can download the source code and the binary from the following links: