简体   繁体   English

在.NET Framework中引用库而不是.NET Standard中的库

[英]Referencing libraries in .NET Framework not in .NET Standard

I'm currently in progress of migrating a class library project to dotnet cli (RC2) from DNX (RC1). 我目前正在从DNX(RC1)将类库项目迁移到dotnet cli(RC2)。 Previously, the project referenced the .NET v4.5.1 framework libraries, and the project.json file looks like this: 以前,该项目引用了.NET v4.5.1框架库,而project.json文件如下所示:

  "frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.Runtime": "4.0.10.0",
        "System.Web": "4.0.0.0",
        "System.DirectoryServices": "4.0.0.0",
        "System.DirectoryServices.AccountManagement": "4.0.0.0",
        "System.ServiceModel": "4.0.0.0",
        "System.ServiceModel.Security": "4.0.0.0"
      }
    }
  }

Now as far as I'm aware, (and I could be wrong,) unlike DNX, the new dotnet Cli doesn't support .NET 4.5.1, and instead supports .NET Standard. 现在据我所知,(我可能错了),与DNX不同,新的dotnet Cli不支持.NET 4.5.1,而是支持.NET Standard。

So problem is, .NET Standard doesn't have all the libraries I want. 问题是,.NET Standard没有我想要的所有库。 What do I have to change so I can reference the .NET 4.5.1 framework libraries? 我需要更改什么才能引用.NET 4.5.1框架库? I read about the imports statement, but I can't get it to work. 我读到了有关进口声明的内容,但我无法让它发挥作用。 Here is what I have so far (updated) : 这是我到目前为止(更新)

  "frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.Runtime": "4.0.10.0",
        "System.Web": "4.0.0.0",
        "System.DirectoryServices": "4.0.0.0",
        "System.DirectoryServices.AccountManagement": "4.0.0.0",
        "System.ServiceModel": "4.0.0.0",
        "System.ServiceModel.Security": "4.0.0.0"
      }
    },
    "netstandard1.5": {
      "imports": [ "dnxcore50", "portable-net451+win8" ]
    }
  }

I get errors such as this: 我得到这样的错误: 无法引用ParallelQuery

I am a bit lost on what else I need to do... Any ideas? 我有点失去了我还需要做什么...有什么想法吗?

dotnet supports net451 . dotnet支持net451 Here's an example of application that has both net451 and netstandard . 这是一个同时net451netstandard的应用程序netstandard

If you app was running on full desktop in RC1, there should be not problem migrating it to full desktop in RC2. 如果您的应用程序在RC1中的完整桌面上运行,那么在RC2中将其迁移到完整桌面应该没有问题。

Try rolling with netcoreapp1.0 instead of netstandard1.5 . 尝试使用netcoreapp1.0而不是netstandard1.5

The new RC2 templates generate the following project.json framework element (by default): 新的RC2模板生成以下project.json框架元素(默认情况下):

"frameworks": {
  "netcoreapp1.0": {
    "imports": [
      "dotnet5.6",
      "dnxcore50",
      "portable-net45+win8"
    ]
  }
},

There's a little discussion about this on GitHub . GitHub上对此有一点讨论。 To quote richlander: 引用richlander:

  • netstandard -> NETStandard.Library (this is expected to work on all .NET netstandard - > NETStandard.Library(预计这适用于所有.NET
  • netstandardapp -> NETStandard.App (same as NETStandard.Library + app hosts) netstandardapp - > NETStandard.App(与NETStandard.Library + app hosts相同)
  • netcoreapp -> Microsoft.NETCore.App (this is the .NET Core base install) netcoreapp - > Microsoft.NETCore.App(这是.NET Core基础安装)

Check on the .NET Platform Standard documentation on GitHub. 查看GitHub上的.NET Platform Standard文档

The netstandard1.5 target moniker targets .NET 4.6.2, which means you can't run it with .NET 4.5.1 projects. netstandard1.5目标名字对象是.NET 4.6.2,这意味着您无法使用.NET 4.5.1项目运行它。

The correct moniker to target .NET 4.5.1 and above is netstandard1.2 . 以.NET 4.5.1及更高版本为目标的正确名字是netstandard1.2

In essence, the target moniker tells you which framework is the lowest supported. 本质上,目标名字对象告诉您哪个框架是最低支持的。 The lower the supported frameworks, the more of them you can target with a single moniker w/o the need of conditional preprocessor directives. 支持的框架越低,您可以使用单个名字对象进行定位,而不需要条件预处理程序指令。

But also, the lower the target moniker, the less of the newer features won't be available (ie Task.CompletedTask ). 但是,目标名字对象越低,新功能就越少(即Task.CompletedTask )。

When you need to target a older framework and want to use new functionality you have to use multiple targets, ie netstandard1.2 which uses the old api and netstandard1.3 that uses the .NET 4.6+ Api and use conditional preprocessor directives to use new Api calls in a specific target. 当您需要定位旧框架并希望使用新功能时,您必须使用多个目标,即netstandard1.2 ,它使用旧的api和netstandard1.3 ,它使用.NET 4.6+ Api并使用条件预处理程序指令来使用新的Api呼叫特定目标。

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

相关问题 .Net Framework dll无法处理.Net标准项目 - .Net Framework dll not working on .Net Standard project 从Net 4.6.1 / 4.7引用Net Standard时出错 - Error referencing Net Standard from Net 4.6.1 / 4.7 引用依赖于ConfigurationManager的.net core 2中的.net框架程序集 - Referencing .net framework assemblies in .net core 2 that rely on the ConfigurationManager 创建一个引用ActionFilters,HTTPContext,HTTPException等的.Net Standard库 - Creating a .Net Standard library referencing ActionFilters, HTTPContext , HTTPException etc .net框架中有哪些wss和moss库 - what are wss and moss libraries available in .net framework .NET Core Web应用程序可以使用.NET Framework类库吗? - Can a .NET Core Web app consume .NET Framework class libraries? 我可以使用在.NET Standard 2.0中为.NET Framework编写的包吗? - Can I use packages written for .NET Framework in .NET Standard 2.0? 如何使用 .NET 框架和 .NET 标准项目构建 Visual Studio 解决方案? - How to build Visual Studio solution with .NET Framework and .NET Standard projects? 从Asp.Net 4.7项目引用.Net Standard 2.0库时出错 - Error when referencing .Net Standard 2.0 library from Asp.Net 4.7 project 使用实体框架在 ASP.NET MVC 3 中自引用 model - Self referencing model in ASP.NET MVC 3 using Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM