0

This should be a simple question but I can't seem to find the answer anywhere.

I've got a project that I'm building to .Net 3.5. I'm trying to include Newtonsoft JSON.Net as a reference, but NuGet is installing a version built to .Net 4.0. This makes it impossible for me to use my compiled assembly in an environment that does not support .Net 4.0.

Is there any way to configure NuGet so that it ensures that the reference is not built to a version of .Net beyond the project settings?

Emily
  • 256
  • 2
  • 14

2 Answers2

1

Maybe you can use this answer to a similar question:

Download old version of package with nuget

It says that you can install an old version of a package You can try to install a version compatible with .NET Framework 3.5, and it will be solved!

;) I hope this helps

Community
  • 1
  • 1
Oscar Bralo
  • 1,912
  • 13
  • 12
1

NuGet will use the project's target framework to pick the correct assembly from the NuGet package. You cannot override this behaviour.

The latest version of the Json.NET NuGet package (6.0.1) contains an assembly specifically for .NET 3.5 so NuGet should automatically pick that one if your project has a target framework of 3.5.

Changing my project's target framework to 3.5 results in the following element being added to the project:

<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>

This is what NuGet uses to determine which assembly to use.

When Json.NET is installed into this project the Newtonsoft.Json.dll file is referenced from the packages\Newtonsoft.Json.6.0.1\lib\net35 directory. That assembly targets .NET 3.5

Matt Ward
  • 47,057
  • 5
  • 93
  • 94