locked
How to set Reference Alias in csproj? RRS feed

  • Question

  • If I have 2 dlls with same name, public key token and culture.
    How can I reference them both in the same C# project?

    Scenarios: having to reference and old and new dll for the sake of upgrade.

    Regards
    Min Chew

    [Edit]
    Solution here

    1. In app.config
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="here token dll"
                              culture="neutral" />
           <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
           <bindingRedirect oldVersion="1.0.0.1-2.0.0.0" newVersion="2.0.0.0" />
           <codeBase version="1.0.0.0" href="folder\namedll.dll" />
           <codeBase version="2.0.0.0" href="folder\namedll.dll" />
        </dependentAssembly>
    </assemblyBinding>
    


    2. Unload and edit the csproj file, and add or set:

    <AutoGenerateBindingRedirect>false</<AutoGenerateBindingRedi‌​rect>



    • Moved by Sabah ShariqMVP Tuesday, March 14, 2017 10:40 AM Moved From Visual C#
    • Edited by Min Chew Monday, May 15, 2017 9:44 AM Removed verbosity, rewrote question and added answer
    Tuesday, March 14, 2017 1:39 AM

Answers

  • Hi Min Chew,

    I have found this issue has been resolved in stackoverflow, I post this link here, and you could mark this reply, which could help others to find the solution.

    http://stackoverflow.com/questions/42715564/using-2-different-versions-of-the-same-dll

    Sincerely,

    Oscsar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Oscar_Wu Friday, March 17, 2017 9:47 AM
    • Marked as answer by Min Chew Thursday, March 23, 2017 4:16 PM
    Thursday, March 16, 2017 3:17 AM

All replies

  • Using BindingRedirect can be tricky at best, you might consider asking here

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=msbuild%2Cwinforms&filter=alltypes&sort=lastpostdesc


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, March 14, 2017 2:19 AM
  • This issue appears to a mix of C# (extern alias) and MSBuild as well as the csproj file, so probably is best in the Visual Studio General section.

    [Edit] Thanks for moving to the appropriate forum

    • Edited by Min Chew Monday, May 15, 2017 9:47 AM
    Tuesday, March 14, 2017 2:30 AM
  • Hi Min Chew,

    I have found this issue has been resolved in stackoverflow, I post this link here, and you could mark this reply, which could help others to find the solution.

    http://stackoverflow.com/questions/42715564/using-2-different-versions-of-the-same-dll

    Sincerely,

    Oscsar


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Oscar_Wu Friday, March 17, 2017 9:47 AM
    • Marked as answer by Min Chew Thursday, March 23, 2017 4:16 PM
    Thursday, March 16, 2017 3:17 AM