开发者

How to get 2 same named .Net Dlls to work together?

开发者 https://www.devze.com 2023-01-30 13:17 出处:网络
I have a certain DLL in my application which works fine by itself. However, the vendor relea开发者_StackOverflow社区sed a newer version of the dll that I am attempting to incorporate using Visual Stud

I have a certain DLL in my application which works fine by itself. However, the vendor relea开发者_StackOverflow社区sed a newer version of the dll that I am attempting to incorporate using Visual Studio. The DLLs share the same filename, while using different namespaces, and the later one is not backwards compatible.

To get VS to even use the newer one I renamed the file which makes sense. However, every time I build the application it only wants to copy the newer dll to the application folder and basically ignores the older dll. I have tried 'copy local' and other settings with no luck. I could probably add the dll to the GAC and be done with it, but don't really want to.

How can I get VS to treat both as totally separate items?


I have a certain DLL in my application which works fine by itself. However, the vendor released a newer version of the dll that I am attempting to incorporate using Visual Studio

Why don't you just remove the old DLL completely and change your code to make the new one work? Why would you want to use both at the same time?


You can deploy the two DLLs to different subdirectories. You'll then need to set up rules in your app.config that tell .NET where to find each version.

An example based on the MSDN page for the <codeBase> element:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <codeBase version="1.0.0.0"
                      href="Version1/myAssembly.dll"/>
            <codeBase version="2.0.0.0"
                      href="Version2/myAssembly.dll"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

At build time you'll need to set Copy Local=false, to prevent Visual Studio from becoming confused. You'll also need a post-build step that sets up the Version1 and Version2 subdirectories.

Note that this assumes you can tell the DLLs apart based on the version number.


I actually solved the problem with a simple post build step to copy the dll to the application folder. VS treated each different, but at build time only copied the later.

0

精彩评论

暂无评论...
验证码 换一张
取 消