2010-06-15 33 views
6

在我的web應用程序中,我使用的是NHibernate.dll。這依賴於下面的彙編。如何解決.Net中衝突的程序集?

'Antlr3.Runtime,版本= 3.1.0.39271, 文化=中立, 公鑰= 3a9cab8f8d22bfb7'

現在再要求我來介紹Antlr3.StringTemplate同一個項目。 dll。它依賴於上述程序集的另一個版本。

如果我使用Antlr3.Runtime.dll滿足NHibernate的Antlr3.StringTemplate版本開始抱怨,反之亦然。

如何解決這樣的情況?

回答

5

您可能可以在web.config中使用assemblyBinding將您的最新版本重定向到舊版本。

例子:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4"/> 
      <bindingRedirect oldVersion="2.1.0.4000" newVersion="2.1.2.4000"/> 
     </dependentAssembly>    
    </assemblyBinding> 
</runtime> 

這直接進入你的web.config中<configuration>節點下。

您可以閱讀回合在這裏: http://msdn.microsoft.com/en-us/library/2fc472t2%28VS.71%29.aspx

4

最簡單的事情就是重新編譯兩個版本。或者,您可以從引用中刪除版本規範(並將特定版本設置爲false)。

1

我們不得不做吉姆羔羊建議的事情。我們構建了所有「第三方庫」的本地版本(我們稱之爲它們),針對強名稱和明確的依賴關係(與下載依賴另一個的dll時可能獲得的內容相關)。我們將這些本地構建放入我們的存儲庫(Subversion)。然後,我們將得到的程序集放入依賴於這些程序集的每個項目根目錄下的「Dependencies/lib」文件夾下。這使我們可以使用其相對路徑位置功能將它們添加爲VS引用。

1

我有同樣的問題。

爲您做了bindingredirect工作?

我已經嘗試過這樣的,但什麼都沒有改變:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="3a9cab8f8d22bfb7" culture="neutral" /> 
      <bindingRedirect oldVersion="*" newVersion="3.1.3.6002" /> 
      <publisherPolicy apply="no"/> 
     </dependentAssembly> 
    </assemblyBinding> 

同樣的錯誤出現。

所以我決定採用將舊版本Antlr3.Runtime組件添加到gac的解決方案。 現在它完美的工作。