Make your.NET program compatible with different versions of the Dll file

  • 2020-05-05 11:09:32
  • OfStack

Some time ago, I wrote an WinForm.NET program. Many library files are referenced, but recently these library files have been modified due to some Bug and algorithms. But the main program file hasn't changed much. So it's not like recompiling the main program. So copy all the new DLL files to the run directory, hoping that the main program can directly call the new version of the library files. It turned out that the library files were all signed with Strong Name. An error occurred when the main program was called, saying that the version of the file could not be found.

Later, I checked MSDN and found that all I had to do was add an runtime node to config.

  < runtime >
          < assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >
                < dependentAssembly >
                      < assemblyIdentity name="MyAssembly"
                                                          publicKeyToken="2b7c3a3291de04"
                                                          culture="neutral" / >
        < bindingRedirect oldVersion="3.0.0.8"
                                                        newVersion="4.1.0.0"/ >

                < /dependentAssembly >
          < /assemblyBinding >
    < /runtime >

But that's only if the two DLL's PublicKeyToken are the same, so you have to sign the same sn file.

Of course, if your library files are not signed by Strong Name at all, you don't need to worry about the version.


Related articles: