简体   繁体   中英

adding class library to web application with net core

I'v created a web application with net core and with this project

"frameworks": {
    "net461": {
      "dependencies": {
        "Core": {
          "target": "project"
        }
      }
    }    
  },

Then I've crated a class library net core with this project

  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }

but when I try to add the class project to web application, VS2015 tell me

The following project are not supported as reference.
WebApplication:
.NETFramework, Version=v4.6.1
ClassLibrary:
.NETStandard, Version=v1.6

How can I add class library to main project?

You have to start your project as a dotnetcore project (see image below) because it seems like you want to add a framework 4.6 file to your dotnetcore application.

dotnetcore项目

for more information about dotnetcore compatibulity check this post Compatibility between dotnetcore and framework 4.5

If you want to target .NET framework 4.6.1, your class library must be .NET Standard 1.4 or lower as suggested on official docs - How to target the .NET Standard

1) Create .NET core class library. project.json looks like this-

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netstandard1.4": {
      "imports": "dnxcore50"
    }
  }
}

2) In ASP.NET Core application (.NET framework), it can reference like below-

  "frameworks": {
    "net461": {
      "dependencies": {
        "ClassLibrary1": {
          "target": "project"
        }
      }
    }    
  },

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