How to build/deploy project that requires multiple versions of the same assembly?

前端 未结 3 1783
梦如初夏
梦如初夏 2020-12-05 16:47

I am working on a project that uses conflict.dll version 6.2, but the project also uses helper.dll that uses conflict.dll version 5.8.

I could install 6.2 and 5.8 in

3条回答
  •  醉话见心
    2020-12-05 17:07

    After many hours of searching and cursing, I found a solution that works and is easy and reliable to implement.

    The problem like all the other answers have pointed out is that all of the following must be satisfied:

    1. Both versions of the DLL must have the same name, otherwise the runtime will complain that the name doesn't match the manifest.
    2. The runtime has to be able to find both assemblies in the search path.
    3. A version redirect is not possible because of breaking changes.
    4. AppDomain.ResolveAssembly never gets called in this example because the assembly has been loaded once already.

    The solution is the following, in steps:

    1. Create a directory in your solution directory such as lib\ with this hierarchy:

      lib\Conflict\v1\Conflict.dll
      lib\Conflict\v2\Conflict.dll

    2. Add the following to your app/web.config:

    
      
        
          
          
          
        
      
    
    
    1. Add a post-build event with an xcopy:

      xcopy $(SolutionDir)\lib $(TargetDir) /Y /S

    2. Build once so that the files are copied. Click on "Project -> Show all files". Right click on bin\Conflict and do Include in Project (saves you from doing it in code). This is necessary to have the files deployed if you package a web application.

    Done!

提交回复
热议问题