示例代码:

"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. 网页提交中文到WEB容器的经历了些什么过程....

    先准备一个网页 <html><meta http-equiv="Content-Type" content="text/html; charset=gb ...

  2. Laravel Composer and ServiceProvider

    Composer and: 创建自定义类库时,按命名空间把文件夹结构组织好 composer.json>autoload>classmap>psr-4 composer dump-a ...

  3. Android 问题汇总(持续更新)

    Q1:Error:(93, 12) 错误: 需要常量表达式 问题描述:这个问题是在添加一个module到项目中时遇到的,主要原因是因为原来module中的R文件是不会以final形式存在的,但是在mo ...

  4. 谈谈一些有趣的CSS题目(六)-- 全兼容的多列均匀布局问题

    开本系列,谈谈一些有趣的 CSS 题目,题目类型天马行空,想到什么说什么,不仅为了拓宽一下解决问题的思路,更涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题 ...

  5. 安装eclipse的maven插件

    我们团队用maven来管理项目需要的库文件,其实以前都没听过maven,第一次接触这个,师兄要我直接去装下这个,开始以为还挺简单的,没想到中间遇到了一些小麻烦,现在把我成功安装maven的过程分享下, ...

  6. Effective前端2:优化html标签

    div { float: left; } .keyboard > div + div { margin-left: 8px; } --> div{display:table-cell;ve ...

  7. Node.js npm 详解

    一.npm简介 安装npm请阅读我之前的文章Hello Node中npm安装那一部分,不过只介绍了linux平台,如果是其它平台,有前辈写了更加详细的介绍. npm的全称:Node Package M ...

  8. 编译器开发系列--Ocelot语言7.中间代码

    Ocelot的中间代码是仿照国外编译器相关图书Modern Compiler Implementation 中所使用的名为Tree 的中间代码设计的.顾名思义,Tree 是一种树形结构,其特征是简单, ...

  9. 类型转换器(InitBinder 初始化绑定器)

    单日期格式 导入jar包 创建FirstController.java @Controller public class FirstController { /** * @param binder * ...

  10. js动态加载css和js

    之前写了一个工具类点此链接里面含有这段代码,感觉用处挺多,特意提出来 var loadUtil = { /* * 方法说明:[动态加载js文件css文件] * 使用方法:loadUtil.loadjs ...