How can I fix assembly version conflicts with JSON.NET after updating NuGet package references in a new ASP.NET MVC 5 project?

后端 未结 11 1602
粉色の甜心
粉色の甜心 2020-11-29 20:42

I created a new ASP.NET MVC 5 web project in VS 2013 (Update 1) then updated all NuGet packages. When I build the project, I get the following warning:

<
相关标签:
11条回答
  • 2020-11-29 21:30

    Remember that with the binding redirection

    oldVersion="0.0.0.0-6.0.0.0"

    You are saying that the old versions of the dll are between version 0.0.0.0 and version 6.0.0.0.

    0 讨论(0)
  • 2020-11-29 21:31

    The final solution to your assembly redirect errors

    Okay, hopefully this should help resolve any (sane) assembly reference discrepancies ...

    1. Check the error.

    1. Check web.config after the assembly redirect. Create one if not exists.

    1. Right-click the reference for the assembly and choose Properties.

    1. Check the Version (not Runtime version) in the Properties table. Copy that.

    1. Paste into the newVersion attribute.

    1. For convenience, change the last part of the oldVersion to something high, round and imaginary.

    Rejoice.

    0 讨论(0)
  • 2020-11-29 21:31

    No one mentioned the following, which in my understanding is the correct solution:

    Go the csproj of the project where the nuget is installed, and set the AutoGEneratedBindingRedirects to false.

    <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>

    Full article in MSDN.

    0 讨论(0)
  • 2020-11-29 21:31

    I had similar issue and just wanted to post an answer for others in my situation.

    I have a solution running a ASP.NET Web Application with multiple other C# class lib projects.

    My ASP.NET Web Application wasn't using json, but other projects where.

    This is how I fixed it:

    1. I made sure all projects where using latest version (6) using NuGet Update on all projects currently using any version of json - this didn't fix the issue
    2. I added json to the web application using NuGet - this fixed the issue (let me dive into why):

    Step 2 was first of all adding a configuration information for json, that suggest that all projects, use the latest version (6) no matter what version they have. Adding the assembly binding to Web.Config is most likely the fix.

    However, step 2 also cleaned up som legacy code. It turned out we have previously used an old version (5) of json in our Web Application and the NuGet folders wasn't deleted when the reference was (I suspect: manually) removed. Adding the latest json (6), removed the old folders (json v5). This might be part of the fix as well.

    0 讨论(0)
  • 2020-11-29 21:36

    Veverke mentioned that it is possible to disable generation of binding redirects by setting AutoGEneratedBindingRedirects to false. Not sure if it's a new thing since this question was posted, but there is an "Skip applying binding redirects" option in Tools/Options/Nuget Packet Manager, which can be toggled. By default it is off, meaning the redirects will be applied. However if you do this, you will have to manage any necessary binding redirects manually.

    0 讨论(0)
提交回复
热议问题