这是我的代码:
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);
}
这些是我要添加到GAC(6.0.1304.0版)的文件
Microsoft.Practices.EnterpriseLibrary.Caching.dllMicrosoft.Practices.EnterpriseLibrary.Common.dllMicrosoft.Practices.EnterpriseLibrary.Data.dllMicrosoft.Practices.EnterpriseLibrary.ExceptionHandling.dllMicrosoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dllMicrosoft.Practices.EnterpriseLibrary.Logging.Database.dllMicrosoft.Practices.EnterpriseLibrary.Logging.dllMicrosoft.Practices.EnterpriseLibrary.PolicyInjection.dllMicrosoft.Practices.EnterpriseLibrary.Security.dllMicrosoft.Practices.EnterpriseLibrary.Validation.dllMicrosoft.Practices.ServiceLocation.dllMicrosoft.Practices.Unity.Configuration.dllMicrosoft.Practices.Unity.dllMicrosoft.Practices.Unity.Interception.Configuration.dllMicrosoft.Practices.Unity.Interception.dll
它们是别人给我的,所以我不确定在哪里可以买到,但肯定可以在线获得。
该代码正确地输出了该列表,并且没有引发任何异常,但是运行gacutil /l
显示仅实际安装了其中的少数几个(下面突出显示)。
可能出什么问题?
可能的重要提示:我的真正问题是,这在具有类似代码(使用EnterpriseServices.Internal.Publish对象)的InstallShield InstallScript安装程序中不起作用。
此方法不会抛出异常! ...为了任何东西!
Publish pub = new Publish(); pub.GacInstall("foo");
没有错误,没有例外。如果路径有效,并且程序集为强名称,它将正确安装在GAC中。效劳于目标.NET框架的程序集版本。即.NET Framework 4.0应用使用GacInstall可以正确安装3.5目标组件,等等。
更新(2011/12/13)-使用ILSpy查看此代码之后功能,我确实发现错误已发送到本地计算机的事件查看器:
不幸的是,事件查看器中的所有事件都只说
在全局程序集缓存中安装失败:foo
事实证明是Installshield。 EnterpriseLibrary程序集的第6版以.NET 4.0为目标,并且由于Installshield仅生成32位.exe,因此它正在调用无法注册.NET 4.0 EnterpriseLibrary程序集的.NET 2.0 System.EnterpriseServices .dll。我添加了一个自定义C#工具来发布通过installscript调用的程序集。这很丑陋,但是必须要做,直到我们可以转换为WIX。
我今天有类似的问题;机器已重新启动。我在非管理员模式下打开Powershell ISE,运行了我运行100多个时间的相同脚本,它的运行方式就像它运行了,但没有运行。问题是要以管理员身份打开。