简体   繁体   English

使用net core将类库添加到Web应用程序

[英]adding class library to web application with net core

I'v created a web application with net core and with this project 我创建了一个带有net core和这个项目的Web应用程序

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

Then I've crated a class library net core with this project 然后我用这个项目创建了一个类库net core

  "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 但是当我尝试将类项目添加到Web应用程序时,VS2015告诉我

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项目启动(请参见下图),因为您似乎想要将一个框架4.6文件添加到您的dotnetcore应用程序中。

dotnetcore项目

for more information about dotnetcore compatibulity check this post Compatibility between dotnetcore and framework 4.5 有关dotnetcore compatiblebulity的更多信息,请查看此帖子dotnetcore和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 如果您想要以.NET Framework 4.6.1为目标,您的类库必须是官方文档中建议的.NET Standard 1.4或更低版本 - 如何定位.NET标准

1) Create .NET core class library. 1)创建.NET核心类库。 project.json looks like this- project.json看起来像这样 -

{
  "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- 2)在ASP.NET核心应用程序(.NET框架)中,它可以像下面一样引用 -

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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