我有一個應用程序參考Microsoft.Data.SqlXml.dll程序集(部分SQLXML)。但是在不同的機器上,取決於它是實時環境還是測試,還是開發人員本地PC,安裝了不同版本的SQLXML。這就產生了一個問題:根據目標機器,我必須編譯應用程序,以防止正確的Microsoft.Data.SqlXml.dll程序集。動態程序集選擇和運行時加載
在Subversion中,我保留在實時環境中使用的csproj和dll文件。當我必須在本地測試利用Microsoft.Data.SqlXml.dll的模塊時,我在項目中更改了引用,並將其還原回來。但有好幾次我忘了回滾更改,並且我檢查了csproj和Microsoft.Data.SqlXml.dll,其版本不符合SQLXML安裝在活動服務器上。結果,我收到運行時錯誤。
我的問題是:有沒有辦法在運行時動態加載程序集?我可以在應用程序的某個地方使用switch語句,根據app.config中的條目載入正確的程序集(例如。env =「live | test | local」)?或者也許有另一種方法來解決這個問題?
謝謝你,帕維爾
確保您的參考文獻中的特定版本設置爲false – Guillaume