Here is my code:
var s = new System.EnterpriseServices.Internal.Publish();
foreach (string file in Directory.EnumerateFiles(@"C:\Program Files\MyFolder\MSPractices"))
{
Console.WriteLine("GACing " + file);
s.GacInstall(file);
}
These are the files I'm trying to GAC (version 6.0.1304.0)
Microsoft.Practices.EnterpriseLibrary.Caching.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.EnterpriseLibrary.Data.dll Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll Microsoft.Practices.EnterpriseLibrary.Logging.dll Microsoft.Practices.EnterpriseLibrary.PolicyInjection.dll Microsoft.Practices.EnterpriseLibrary.Security.dll Microsoft.Practices.EnterpriseLibrary.Validation.dll Microsoft.Practices.ServiceLocation.dll Microsoft.Practices.Unity.Configuration.dll Microsoft.Practices.Unity.dll Microsoft.Practices.Unity.Interception.Configuration.dll Microsoft.Practices.Unity.Interception.dll
They were given to me by someone else so I'm not sure where you can get them but surely they're available online.
The code correctly outputs that list and does not throw any exceptions but running gacutil /l
reveals that only a few of them (highlighted below) are actually installed.
What can be going wrong?
POSSIBLY IMPORTANT: My real issue is that this doesn't work in my InstallShield InstallScript installer with similar code (using the EnterpriseServices.Internal.Publish object).
This method throws no exception! ...for anything!
Publish pub = new Publish(); pub.GacInstall("foo");
No error, no exception. If the path is valid, and the assembly is strongly named, it will get properly installed in the GAC. Works for target .NET Frame version of assembly. I.e. a .NET Framework 4.0 app using GacInstall will properly install a 3.5 targeted assembly, etc.
Update (2011/12/13) - After using ILSpy to look at the code for this function, I did discover that errors are sent to the local machine's Event Viewer:
Unfortunately, all events in the event viewer say only
Installation in the global assembly cache failed: foo
It did turn out to be Installshield. Version 6 of the EnterpriseLibrary assemblies target .NET 4.0 and, because Installshield only builds 32-bit .exes, it was calling the .NET 2.0 System.EnterpriseServices .dll which couldn't register the .NET 4.0 EnterpriseLibrary assemblies. I've added a custom C# tool to publish the assemblies that is called via installscript. It's ugly but it'll have to do until we can convert to WIX.