示例代码:

"frameworks": {
"netcoreapp1.0.0": { "imports" : "portable-net45+win81" }
}

importsis a way to use packages that were not designed for that framework. Basically you tell it "Use those targets even though they don't seem to be supported. I know what I'm doing".

注:摘录自 Frameworks and imports sections in project.json: what are they?

上面这段解释什么意思?字面意思:imports是使用程序包的一种方式,虽然不是为这种框架设计的,基本上你告诉它“使用这些目标框架,即使它们似乎不被支持,但我知道我在做什么”,翻译的比较生硬,你可以这样理解:imports的作用是各个平台之间的兼容处理,并且针对的是不支持的程序包。

概念理解还是有些问题,再来看下面的解释。


摘录:What it says right here is that I’m targeting the netcoreapp1.0 framework (which is the default framework for a .NET Core application). With the “imports” bit I’m also stating that any dependency I want to include that targets dnxcore50 should be treated as compatible with netcoreapp1.0. Basically I’m instructing the tooling to ignore the fact that dnxcore50 isn’t the same thing as netcoreapp1.0 because I know it is the same thing (or more precisely Microsoft knows that they are the same).

翻译:需要说明的是,如果目标框架平台是 netcoreapp1.0,使用imports dnxcore50,就可以使 netcoreapp1.0 和 dnxcore50 平台兼容,并且使工具忽略 netcoreapp1.0 和 dnxcore50 不一样的事实,因为我知道它是相同的事情(或更确切的 Microsoft 知道他们是相同的)。

解释:举一个示例,比如 WebApi.Client 程序包,分别实现了 netcoreapp1.0 和 net451 平台版本(代码完全一样,只是基于的平台不一样),然后有一个应用程序是 netcoreapp1.0 平台的,然后它去引用 net451 平台的 WebApi.Client 程序包,在 VS2015 中会报不支持平台错误,虽然两种平台版本的代码完全一样,但还是不能跨平台饮用,imports就是解决这个问题的,并且使 VS2015 忽略这个错误。

摘录:A word of warning is in order here though. Theoretically I could “import” any framework that’s currently out there I can install pretty much any package into my project. However, that doesn’t mean that my application will actually run and work. If a package I installed into my project is using an API that’s not available on the platform that my application will be running on it will simply fail at runtime.

Therefore you should be careful when using “imports” and make sure that you test your application properly on the actual framework it will be running on. Think of it as when you’re using “imports” you’ve turned off the tooling and you are on your own and its your job to make sure that your application works correctly.

翻译:警告在这里,理论上,我可以imports任何框架平台,然后安装所有平台的程序包。然而,这并不意味着我的应用程序可以实际运行和工作。如果我安装到我项目的程序包,在这个平台上 API 不可用,我的应用程序在运行时将是失败的。

因此,在使用imports时应该小心,要确保在平台框架上,应用程序可以实际正常运行。想象下,当你使用了imports,你就关闭了 VS2015 的提示,你就要确保它是正常工作的。

解释:举个例子,比如 WebApi.Client 程序包,分别实现了 netcoreapp1.0 和 net451 平台版本(代码完全不一样,内部实现使用了不同平台的 API),然后有一个应用程序是 netcoreapp1.0 平台的,然后它去引用 net451 平台的 WebApi.Client 程序包,需要使用imports net451,在 VS2015 编译完全没什么问题,但在 netcoreapp1.0 平台实际运行的时候,就会出错了,因为不同平台的 WebApi.Client 程序包,使用了不同平台的 API。

注:摘录自 .NET Platform Standard and the magic of “imports”

翻译的比较差,但大概意思是懂了,总的来说,使用imports,只是解决了在 VS2015 中平台不支持的错误提示,但并不一定说明实际是正常运行的,所以,要在实际运行环境中,测试引用其他平台的程序包,执行是否有问题。

ASP.NET Core project.json imports 是什么意思?的更多相关文章

  1. [asp.net core]project.json(1)

    摘要 前面介绍了使用vs2015新建asp.net core web的内容,这篇文章学习下project.json文件的内容. project.json 原文:https://docs.microso ...

  2. [asp.net core]project.json(2)

    摘要 上篇文章介绍了project.json中的一部分属性.属性真的比较多,所以分开了,考虑到其中的英文比较简单,也不再进行翻译了,从英文原文中,直接粘贴过来了. project.json(1) pr ...

  3. ASP.NET Core launchsettings.json 文件

    ASP.NET Core launchsettings.json 文件 在本节中,我们将讨论在 ASP.NET Core 项目中launchsettings.json文件的重要性. launchset ...

  4. ASP.NET Core 返回 Json DateTime 格式

    ASP.NET Core 返回 Json 格式的时候,如果返回数据中有DateTime类型,如何自定义其格式呢?配置如下: services.AddMvc().AddJsonOptions(opt = ...

  5. [转]Setting the NLog database connection string in the ASP.NET Core appsettings.json

    本文转自:https://damienbod.com/2016/09/22/setting-the-nlog-database-connection-string-in-the-asp-net-cor ...

  6. ASP.NET Core appsettings.json 文件

    ASP.NET Core appsettings.json 文件 在本节中,我们将讨论 ASP.NET Core 项目中appsettings.json文件的重要性. 在以前的 ASP.NET 版本中 ...

  7. ASP.NET Core 在 JSON 文件中配置依赖注入

    前言 在上一篇文章中写了如何在MVC中配置全局路由前缀,今天给大家介绍一下如何在在 json 文件中配置依赖注入. 在以前的 ASP.NET 4+ (MVC,Web Api,Owin,SingalR等 ...

  8. 【ASP.NET Core】JSON Patch 使用简述

    JSON Patch 是啥玩意儿?不知道,直接翻译吧,就叫它“Json 补丁”吧.干吗用的呢?当然是用来修改 JSON 文档的了.那咋修改呢?比较常见有四大操作:AMRR. 咋解释呢? A—— Add ...

  9. Asp.Net Core中Json序列化处理整理

    一.Asp.Net Core中的Json序列化处理使用的是Newtonsoft.Json,更多参考:C# Newtonsoft.Json JsonSerializerSettings配置序列化操作,C ...

随机推荐

  1. ASP.NET Aries 入门开发教程2:配置出一个简单的列表页面

    前言: 朋友们都期待我稳定地工作,但创业公司若要躺下,也非意念可控. 若人生注定了风雨飘摇,那就雨中前行了. 最机开始看聊新的工作机会,欢迎推荐,创业公司也可! 同时,趁着自由时间,抓紧把这系列教程给 ...

  2. .NET基础拾遗(5)多线程开发基础

    Index : (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理基础 (3)字符串.集合与流 (4)委托.事件.反射与特性 (5)多线程开发基础 (6)ADO.NET与数据库开 ...

  3. git 命令

    切换仓库地址: git remote set-url origin xxx.git切换分支:git checkout name撤销修改:git checkout -- file删除文件:git rm  ...

  4. Spring Enable annotation – writing a custom Enable annotation

    原文地址:https://www.javacodegeeks.com/2015/04/spring-enable-annotation-writing-a-custom-enable-annotati ...

  5. PayPal高级工程总监:读完这100篇论文 就能成大数据高手(附论文下载)

    100 open source Big Data architecture papers for data professionals. 读完这100篇论文 就能成大数据高手 作者 白宁超 2016年 ...

  6. Hadoop学习之旅二:HDFS

    本文基于Hadoop1.X 概述 分布式文件系统主要用来解决如下几个问题: 读写大文件 加速运算 对于某些体积巨大的文件,比如其大小超过了计算机文件系统所能存放的最大限制或者是其大小甚至超过了计算机整 ...

  7. JAVA回调机制解析

    一.回调机制概述     回调机制在JAVA代码中一直遇到,但之前不懂其原理,几乎都是绕着走.俗话说做不愿意做的事情叫做突破,故诞生了该文章,算是新年的新气象,新突破!     回调机制是什么?其实回 ...

  8. [转载]一个标准java程序员的进阶过程

    第一阶段:Java程序员 技术名称 内                 容 说明 Java语法基础 基本语法.数组.类.继承.多态.抽象类.接口.object对象.常用类(Math\Arrarys\S ...

  9. Android Retrofit 2.0 使用-补充篇

    推荐阅读,猛戳: 1.Android MVP 实例 2.Android Retrofit 2.0使用 3.RxJava 4.RxBus 5.Android MVP+Retrofit+RxJava实践小 ...

  10. A*算法应用[转]

    转自:http://www.cnblogs.com/zhoug2020/p/3468167.html 这是一篇十分精彩/易懂的博客,感谢原博主!本文通过自己的理解在原博文基础上突出一些重点字眼,句子. ...