Reputation: 688
I have 2 projects in my solution. First is portable library targeting .NET Standard 1.3. This library has a dependency to Json.NET. Its project.json looks like following:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"netstandard1.3": {}
}
}
Library consists of just this simple class:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestLibrary
{
public class TestClass
{
public static string Foo() {
return JsonConvert.SerializeObject(42);
}
}
}
Second project is console application targeting full .NET 4.6.1 framework. This console app references library mentioned above. Code is following:
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var x = TestLibrary.TestClass.Foo();
}
}
}
I'm able to build and run it, but calling TestLibrary.TestClass.Foo()
results in following exception:
Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.":"Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"
There is no Newtonsoft.Json.dll
in my bin folder.
I have Visual Studio 2015 Update 3 (KB3165756) installed (14.0.25431.01, released on 09/14/2016) as well as .NET Core 1.0.1 VS 2015 Tooling Preview 2.
After spending too much time googling, I'm not sure whether a) I'm doing something wrong b) tooling doesn't support this scenario yet c) my Visual Studio installation is somehow broken.
EDIT: Here is complete solution to reproduce.
Upvotes: 3
Views: 2198
Reputation: 1906
You do not have to install dependencies of .NET Standard libraries manually.
Microsoft finally admitted this is a problem and will fix it, expectantly, in NuGet version 4.0.1, the first update to NuGet 4 after VS 2017 ships.
The cleanest workaround now is to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
to a legacy (.NET 4.6.1. app in this case) project. However according to Rob Relyea MS will ignore this property after RTM so another workaround is <PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/>
.
Another workaround is to pack a .NET Standard library into NuGet package like in that answer, but it is not the easiest way.
Upvotes: 2
Reputation: 3776
The PCL library project manages packages with project.json file, but the common .NET Framework projects manage NuGet packages with packages.config.
I have tested if I install the Newtonsoft.Json package in your Console application manually, it could run successful. And if I reference the PCL library project using .NET Core Console app which also manage NuGet packages with project.json file, the solution could run successful too.
So in your situation, you need to install the NuGet packages that in PCL library project into your Console application manually.
Upvotes: 2