Dot-Net

.NET:載入同一個 DLL 的兩個版本

  • May 15, 2019

我需要載入同一個 DLL 的兩個版本以比較它們的輸出。我假設我可以為此使用 AppDomains,但我需要一些指導。

好吧,這實際上比我想像的要容易得多。

   m_Assembly1 = Reflection.Assembly.LoadFile(IO.Path.Combine(System.Environment.CurrentDirectory, "Old Version\Some.dll"))
   m_Assembly2 = Reflection.Assembly.LoadFile(IO.Path.Combine(System.Environment.CurrentDirectory, "New Version\Some.dll"))

   Console.WriteLine("Old Version: " & m_Assembly1.GetName.Version.ToString)
   Console.WriteLine("New Version: " & m_Assembly2.GetName.Version.ToString)

   m_OldObject = m_Assembly1.CreateInstance("FullClassName")
   m_NewObject = m_Assembly2.CreateInstance("FullClassName")

從這裡開始,我使用後期綁定和/或反射來執行我的測試。

引用自:https://stackoverflow.com/questions/2016990