How to install json.net .net 4.0 compatible version?

To avoid the problem described here:

Failed to load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib

I am trying to create my project for targeting .net 4.0 instead of 4.5 (in Visual Studio 2013), but I am getting the following errors:

  • The type or namespace name 'Newtonsoft' could not be found (are you missing the using directive or assembly reference?)

    The main link "Newtonsoft.Json" cannot be resolved because it was created against the framework ".NETFramework, Version = v4.5". This is a higher version than the current target environment is ".NETFramework, Version = v4.0".

So, I would like to install a version of json.net compatible with .net 4.0. I see that the downloaded NuGet package contains the lib / 4.0 directory in addition to lib / 4.5, but I cannot figure out how to get the package manager to use this instead of version 4.5.

How can I get a design solution for buikd using a version of json.net that is compatible with .net 4.0, and not one that works only with .net 4.5?

+7
source share
2 answers

Run update-package -reinstall from the package manager console.

+4
source share

As I found this:

  • Close the VS solution.
  • Manually edit all packages.config files in your solution to indicate the version you need (for example, for me, I changed them to id = "Newtonsoft.Json" version = "6.0.3" targetFramework = "net40")
  • Go to the packages folder on the disk for your solution and delete the version there
  • Remove the dll and xml Newtonsoft.Json from the output path for your solution.
  • Remove bin directories for projects that use json.net in your solution.
  • open the solution in visual studio
  • open the package manager (use the menu: tools, NuGet package manager, manage NuGet packages to solve in my version of VS)
  • At the top of the package manager dialog box, he complains about mssing packages - click Restore
  • Go to the packages folder on the disk for your solution and make sure that it has installed the correct version
  • Clean up the solution (otherwise the dll and xml Newtonsoft.Json will not be replaced in the output path)
  • Build and verify that the DLL in the output path is the correct version and for the correct structure (NewtonSoft puts the .net version in the file description for older versions)

If any of these steps could be optimized, I would like to know how ...

+1
source share

All Articles