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 ...
随机推荐
- Html Agility Pack 解析Html
Hello 好久不见 哈哈,今天给大家分享一个解析Html的类库 Html Agility Pack.这个适用于想获取某网页里面的部分内容.今天就拿我的Csdn的博客列表来举例. 打开页面 用Fir ...
- SQL Server on Linux 理由浅析
SQL Server on Linux 理由浅析 今天的爆炸性新闻<SQL Server on Linux>基本上在各大科技媒体上刷屏了 大家看到这个新闻都觉得非常震精,而美股,今天微软开 ...
- Centos——安装JDK
写在前面: Just mark! 创建linux虚拟机的时候经常要安装JDK,配置环境变量,却又经常忘记,这里记录一下. 环境:Centos-6.8-x86_64-minimal JDK :jdk-7 ...
- 【WCF】自定义错误处理(IErrorHandler接口的用法)
当被调用的服务操作发生异常时,可以直接把异常的原始内容传回给客户端.在WCF中,服务器传回客户端的异常,通常会使用 FaultException,该异常由这么几个东东组成: 1.Action:在服务调 ...
- JavaScript之职责链模式
一.概述 职责链模式(Chain of responsibility),就是使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这个对象连成一条链,并沿着这条链传递该请求,直到有 ...
- TortoiseGit 文件比对工具使用 Beyond Compare 和 DiffMerge
TortoiseGit 内置的文件比对工具是 TortoiseMerge,用于文件比对和解决冲突合并,TortoiseGit 还支持外部的比对工具使用,比如 Beyond Compare 和 Diff ...
- Django
一.Django 简介 Django 是一个由 Python 写成的开放源代码的 Web 应用框架.它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是 CMS(内容管理系统) ...
- 在centos7上安装Jenkins
在centos7上安装Jenkins 安装 添加yum repos,然后安装 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins ...
- git快速get
配置:git config --global user.name 'yangshaoxiang' git config --global user.email '254135495@qq.com' s ...
- appium+robotframework环境搭建
appium+robotframework环境搭建步骤(Windows系统的appium自动化测试,只适用于测试安卓机:ios机需要在mac搭建appium环境后测试) 搭建步骤,共分为3部分: 一. ...