Rather than have a user try to find it, we can leverage the .Net Framework directly to perform GAC (un)install.
This is ideal for use in a Console application to (un)install a specific file.
Microsoft Links
Publish.GacInstall Method
Publish.GacRemove Method
Example:
Simple installer class that is installing the MyAssembly.dll assembly into the GAC.
ToDo: This may be more useful if it accepts the file name as a parameter.
using System;
using System.IO;
using System.EnterpriseServices.Internal;
class GACInstaller
{
static void Main(string[] args)
{
string assemblyName = "MyAssembly.dll";
Console.WriteLine();
Publish objPublish = new Publish();
string file = Path.Combine(Directory.GetCurrentDirectory(), assemblyName);
if (File.Exists(file))
{
try
{
objPublish.GacInstall(file);
Console.WriteLine($"'{assemblyName}' successfully added to the cache");
}
catch (Exception error)
{
Console.WriteLine($"Error encountered when adding '{assemblyName}' to cache: {error.Message}");
}
}
else
{
Console.WriteLine($"Cannot find specified '{assemblyName}' in current directory");
}
}
}
No comments:
Post a Comment