2015-12-02 63 views
4

這裏是我的代碼:System.EnterpriseServices.Internal.Publish.GacInstall不工作,但沒有任何錯誤

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.dll Microsoft.Practices.EnterpriseLibrary.Common.dll Microsoft.Practices.EnterpriseLibrary.Data.dll Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll Microsoft.Practices.EnterpriseLibr ary.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 微軟。 Practices.Unity.Interception.dll

他們是由別人給我的,所以我不確定你能在哪裏得到他們,但肯定他們在網上提供。

該代碼正確地輸出該列表並且不會拋出任何異常,但運行gacutil /l表明實際上只安裝了其中的幾個(下面突出顯示)。

enter image description here

有什麼可以去錯了嗎?

可能很重要:我的真正問題是,在我的InstallShield InstallScript安裝程序中使用類似的代碼(使用EnterpriseServices.Internal.Publish對象)不起作用。

UPDATE

此方法拋出也不例外! ...爲了任何東西! Publish pub = new Publish(); pub.GacInstall("foo");

沒有錯誤,沒有例外。如果路徑有效,並且程序集名爲 ,則它將正確安裝在GAC中。適用於目標.NET Frame版本的 。即使用GacInstall的.NET Framework 4.0應用程序 將正確安裝3.5目標程序集等。

更新(2011/12/13) - 使用ILSpy看看這個 函數的代碼後,我發現,錯誤被髮送到本地計算機的 事件查看器:

不幸的是,在事件查看器事件只說

安裝在全局程序集緩存失敗:富

回答

1

它確實是Installshield。 EnterpriseLibrary程序集版本6的目標是.NET 4.0,因爲Installshield只生成32位.exes,所以它調用了無法註冊.NET 4.0 EnterpriseLibrary程序集的.NET 2.0 System.EnterpriseServices .dll。我添加了一個定製的C#工具來發布通過installscript調用的程序集。這是醜陋的,但它必須做,直到我們可以轉換爲WIX。

3

你已經凸輪e得出結論,這些方法並不總是有用的。

如果你想要一個更強大的方法,你可以從C#使用GAC/Fusion API文檔herehere。在C#中的示例可以找到here(感謝Hans Passant),herehere

您也可以嘗試gacutil.exe來查看問題所在。您可以在安裝了Visual Studio的計算機上找到它。

相關問題