简体   繁体   中英

Add Assembly to Class Library in VS 2015

Have used Visual Studio for years and are now trying to create my first project in Visual Studio 2015.

I have create an MVC project and I am now interrested in adding a new project which will act as my data layer. Lets call the project MyProj. So I created a new Web Class Library called MyProj.Data. I also installed the newest EntityFramework (6.1.3) using NuGet to this project.

Now I want to create a class which should act as my EntityTypeConfiguration like:

public class GadgetConfiguration : EntityTypeConfiguration<Gadget>
{
  ....
}

Problem is that EntityTypeConfiguration is not recognised. Reharper says: Reference 'EntityFramework' and use 'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration'

Problem is that (as far as I see it) in folder References -> .NET Platform I can see my EntityFramework. So that should be referenced. But I cannot find System.Data.Entity in the references.

When I try to Add Reference, my Assemblies tab say 'No items found'. If I click the "Browse..." button I am told that "Project does not have target frameworks specified".

Then I tried adding v4.5 to the MyProj.Data.xproj file (under ...) but that didn't change a thing.

Then I changed the frameworks part of the project.json file from

"frameworks": {
 "dotnet": { }
 }

to

"frameworks": {
"dotnet": { },
"dnx451": {
  "frameworkAssemblies": {
    "System.Data": "4.0.0.0",
    "System.Data.Entity": "4.0.0.0"
  }
}

Now I can see the System.Data and System.Data.Entity. I can also add more assemblies from the References now. But I still cannot USE them in my classes. Neither by typing

using EntityFramework

or

using System.Data

or by referencing directly like

public class GadgetConfiguration : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<Gadget>

How can I reference/use the needed assembly?

Okay, solution was simple... I Created a Web Class Library which is to be used when you want to create a class library as a NuGet package. This was NOT what I wanted (you couldn't know from my initial description).

So solution was to drop the Web Class Library and create a Windows Class Library instead. It now works!

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