简体   繁体   中英

Can't reference EF in ASP.NET 5 in class library

Can't reference EF in ASP.NET 5 in class library. I have no idea why. Visual Studio shows nothing. I'm trying to reference EF using ALT + ENTER (resharper shortcut). How can I solve my problem?

在此处输入图片说明

I haven't had any luck with Resharper pulling in NuGet packages for me just yet. I'm running the latest version too. I think this is because ASP.NET 5 is still in RC so full support isn't ready yet.

To address your problem:

Chances are your class library is targetting net451 and dotnet5.4 :

  "frameworks": {
    "net451": { },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
        // etc
      }
    }
  }

However, this requires that your dependencies are also supporting dotnet5.4 . I've found that a lot of packages have not moved to this new moniker yet. To get around it, I had to change my target to dnxcore50 and get rid of net451 (because I'm trying to target only .NET core and not the full .NET framework).

This explains why you're able to use EF in a console project - it uses dnxcore50 by default :)

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
        // etc
      }
    }
  }

After this change, Resharper is able to see new packages I've added as dependencies and I can hit Alt+Enter to pull them in. Note: I do have to still add the packages manually in project.json or via the NuGet package manager. After I've done that Resharper plays nice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM