ASP.NET Core project.json imports 是什么意思?
示例代码:
"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 是什么意思?的更多相关文章
- [asp.net core]project.json(1)
摘要 前面介绍了使用vs2015新建asp.net core web的内容,这篇文章学习下project.json文件的内容. project.json 原文:https://docs.microso ...
- [asp.net core]project.json(2)
摘要 上篇文章介绍了project.json中的一部分属性.属性真的比较多,所以分开了,考虑到其中的英文比较简单,也不再进行翻译了,从英文原文中,直接粘贴过来了. project.json(1) pr ...
- ASP.NET Core launchsettings.json 文件
ASP.NET Core launchsettings.json 文件 在本节中,我们将讨论在 ASP.NET Core 项目中launchsettings.json文件的重要性. launchset ...
- ASP.NET Core 返回 Json DateTime 格式
ASP.NET Core 返回 Json 格式的时候,如果返回数据中有DateTime类型,如何自定义其格式呢?配置如下: services.AddMvc().AddJsonOptions(opt = ...
- [转]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 ...
- ASP.NET Core appsettings.json 文件
ASP.NET Core appsettings.json 文件 在本节中,我们将讨论 ASP.NET Core 项目中appsettings.json文件的重要性. 在以前的 ASP.NET 版本中 ...
- ASP.NET Core 在 JSON 文件中配置依赖注入
前言 在上一篇文章中写了如何在MVC中配置全局路由前缀,今天给大家介绍一下如何在在 json 文件中配置依赖注入. 在以前的 ASP.NET 4+ (MVC,Web Api,Owin,SingalR等 ...
- 【ASP.NET Core】JSON Patch 使用简述
JSON Patch 是啥玩意儿?不知道,直接翻译吧,就叫它“Json 补丁”吧.干吗用的呢?当然是用来修改 JSON 文档的了.那咋修改呢?比较常见有四大操作:AMRR. 咋解释呢? A—— Add ...
- Asp.Net Core中Json序列化处理整理
一.Asp.Net Core中的Json序列化处理使用的是Newtonsoft.Json,更多参考:C# Newtonsoft.Json JsonSerializerSettings配置序列化操作,C ...
随机推荐
- warensoft unity3d 更新说明
warensoft unity3d 组件的Alpha版本已经发布了将近一年,很多网友发送了改进的Email,感谢大家的支持. Warensoft Unity3D组件将继续更新,将改进的功能如下: 1. ...
- 设计模式之结构类模式大PK
结构类模式大PK 结构类模式包括适配器模式.桥梁模式.组合模式.装饰模式.门面模式.享元模式和代理模式.之所以称其为结构类模式,是因 ...
- DOM、BOM 操作超级集合
本章内容: 定义 节点类型 节点关系 选择器 样式操作方法style 表格操作方法 表单操作方法 元素节点ELEMENT 属性节点attributes 文本节点TEXT 文档节点 Document 位 ...
- 【读书】PHP程序员要读的书目(不断完善中)
本文地址 分享提纲: 1. PHP 2. Linux 3. Apache/Nginx 4. Mysql 5.设计模式/架构 6. 缓存并发 7. 其他语言 8. 代码基础 9. 大前端 10. 管理生 ...
- Android之Dedug--Circular dependencies cannot exist in AnimatorSet
今日,在学习AnimatorSet时,使用play.with.after.before时,代码书写如下: ObjectAnimator animator1 = ObjectAnimator.ofFlo ...
- Lucene4.4.0 开发之排序
排序是对于全文检索来言是一个必不可少的功能,在实际运用中,排序功能能在某些时候给我们带来很大的方便,比如在淘宝,京东等一些电商网站我们可能通过排序来快速找到价格最便宜的商品,或者通过排序来找到评论数最 ...
- Python学习基础
1.使用范围: 大数据 .图像处理.web .运维.爬虫.自动化.科学计算 2.准备环境: linux/mac python 3.5.2 ipython vim/sublime/atom 3.列表 3 ...
- Linux根文件系统分析之init和busybox
Hi,大家好!我是CrazyCatJack.今天给大家讲解Linux根文件系统的init进程和busybox的配置及编译. 先简单介绍一下,作为一个嵌入式系统,要想在硬件上正常使用的话.它的软件组成大 ...
- OpenGL: 纹理采样 texture sample
Sampler (GLSL) Sampler通常是在Fragment shader(片元着色器)内定义的,这是一个uniform类型的变量,即处理不同的片元时这个变量是一致不变的.一个sampler和 ...
- No plugin found for prefix ‘jetty’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories
maven配置文件(最大的那个)的<pluginGroups></pluginGroups>增加一行如下<pluginGroups><pluginGroup& ...