Nuget packages aren't copied to output when using .NETStandard

2.5k views Asked by At

I want to share a project between a WPF (.NET 4.6) application and a .NET Core application. To do this I've made a .NET Standard library by making a portable library initially and converting it in Visual Studio 2015 to .NETStandard version 1.3.

However, the .NETStandard library needs to reference Entity Framework (for example) and so I've added this dependency in the project.json and everything builds happily. However, when I actually run the application, I get a File Not Found exception as soon as I actually try to load data using the Entity Framework library. This is expected, since none of the nuget packages when using .NETStandard are copied to the output directory (unlike using nuget for normal .NET), so I can see the reason for the exception.

How do I fix this/get the nuget dependencies to be copied to output when using a .NETStandard library and referencing from a .NET 4.6 project? (Below is my project.json and happy to add more code if needed).

{
  "supports": {},
  "dependencies": {
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.1.0",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.1"
   },
  "frameworks": {
    "netstandard1.3": {}
  }
}
1

There are 1 answers

0
Sourcerer On

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 project.

However according to Rob Relyea MS will ignore this property after RTM so another workaround is <PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/>.