在迁移.net core的过程中,第一步就是要把.net framework 工程的目标框架改为.net core2.0,但是官网却没有提供转换工具,需要我们自己动手完成了。.net framework 工程迁移为.net core工程大体上有两种方案:

1.创建一个.net core的工程,然后把所有的文件挪过去。这是比较笨的一种办法,如果工程比较小,还好弄。如果有几百工程,那就哭了。

2.通过编辑.csproj文件,强制把工程迁移到.net core下。

今天给大家分享的就是,如何通过修改.csproj文件的方式,把.net framework 工程迁移到.net core下。

步骤一:通过VS2017打开.net framework 解决方案,卸载指定的项目后,打开.csproj文件。

步骤二:移除两个 import引用

步骤三:移除 Release、Debug编译的配置信息

步骤四:修改 Project节点属性:

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

替换为:

<Project Sdk="Microsoft.NET.Sdk">

步骤五:移除TargetFrameworkVersion信息,增加信息:<TargetFramework>netcoreapp2.0</TargetFramework>

步骤六:重新加载项目

步骤七:在已经加载的 .net core项目上,继续编辑csproj文件。

步骤八:移除文件列表信息。

步骤九:移除AssemblyInfo.cs文件。

步骤十:移除.net framework工程中隐藏的文件。因为.net core 工程不支持排除文件,所以在完成上述迁移后,原来隐藏的文件会自动添加到工程中,对这些垃圾文件,请识别后,手工删除即可。

步骤十一:重新添加nuget包引用。.net framework 对nuget包的引用信息是存储到packages.config中的。此文件已经在.net core中移除。请根据packages.config信息,在项目中重新添加nuget引用。引用信息将会自动添加到csproj文件中。

步骤十二:编译工程。说一下,很多.net framework的API在.net core中已经没有了,正在迁移前,请看一下下面的.net core的资料。

======================================

1. 不支持序列化和xml操作

*(需要:Install-Package System.Xml.XmlDocument , Install-Package System.Runtime.Serialization.Formatters -Pre, Install-Package System.Xml.XmlSerializer)

* XmlDocument

* XmlIgnore

* Serializable

* XmlNode

* BinaryFormatter

* SoapFormatter

* InflaterInputStream

* DataContractSerializer (Install-Package System.Runtime.Serialization.Xml)

* DataContractJsonSerializer(Install-Package System.Runtime.Serialization.Json)

2. 部分反射需要改造, you need to reference the following:

* System.Reflection

* System.Reflection.Primitives

* System.Reflection.Extensions

* System.Reflection.TypeExtensions

* If you need IL generation then add System.Reflection.Emit andSystem.Reflection.Emit.ILGeneration

* 比如Type.GetProperties()要改为Type.GetTypeInfo().GetProperties()

* 不支持Assembly.GetExecutingAssembly() https://forums.asp.net/t/2001385.aspx

3. Tasks and Threading and async/await are available, but you will have to reference the following:

* System.Threading.Thread

* System.Threading.Tasks

4. Sockets are available but you need to reference the following:

* System.Net.Sockets.

* System.Net.Security if you want SslStream.

* Also, socket.Close() is now socket.Dispose()

5. Remoting,It's used for cross-AppDomain communication, which is no longer supported. Also, Remoting requires runtime support, which is expensive to maintain.

6. Async is supported (see above point) but the older IAsyncResult-based async is not supported. You will have to disable those sections using #if tags or upgrade to async/await.

7. Serialization by converting data to and from Binary is unsupported, but XML, and JSON serialization is. (see System.Runtime.Serialization.Xml and System.Runtime.Serialization.Json)

8. Crypto is available but many classes are renamed and refactored, for eg. new SHA1CryptoServiceProvider() is now SHA256.Create().

9. StackTrace is available but you need the extra System.Diagnostics.StackTrace, so if its not essential you may want to remove from your code rather than add an additional dependency

10. XAML is unsupported but if you are targeting UWP you will have to use the Windows RT XAML APIs.

11. 不支持部分对象:

* ArrayList

* Hashtable

* HybridDictionary

* BindingList

* Thread(Install-Package System.Threading.Thread)

* Process(Install-Package System.Diagnostics.Process)

* HttpContext

* AppDomain

* DataSet / DataTable / DBNull。DataTable and DataSet is not available in the System.Data namespace but other features like the provider model and SQL client are available.

12. 注册表无法访问

* RegistryKey

13. 不支持相关配置对象:

* ConfigurationManager

* WebConfigurationManager

* ConfigurationSection

14. 不支持绘图

* System.Drawing

* System.Drawing.Size

15. 无法使用相关Web对象

*System.Web.HttpUtility.HtmlDecode

16. 很多Stream没有了Close()方法,直接替换为Dispose()

17. DateTime.Now.ToShortDateString() 替换为 DateTime.Now.ToString("yyyy-MM-dd")

18. 不支持部分Attribute

* DescriptionAttribute

19. WebResponse/WebRequest对象有变化

* 不支持:httpWebResponse.ContentEncoding,无法识别是否响应加了GZip,也或许能自动识别

* 不支持:httpWebRequest.Referer / .UserAgent 无法设置请求浏览器和来源地址

20. Some key missing components: (source)

* System.AppDomain - App Domains

* System.Drawing.Image - Graphics, Bitmap Images

* System.DirectoryServices - LDAP, Active Directory

* System.Transactions - ambient transactions, distributed transactions

* System.Xml.Xsl - XSLT

* System.Xml.Schema - XSD

* System.Net.Mail - Sending Email

* System.Runtime.Remoting - Remoting, RPC

* System.Runtime.Serialization.Xml - Binary Serialization

* System.IO.Ports - Serial Port

* System.Workflow - Windows Workflow Foundation

.net core 2.0学习笔记(四):迁移.net framework 工程到.net core的更多相关文章

  1. 一起学ASP.NET Core 2.0学习笔记(二): ef core2.0 及mysql provider 、Fluent API相关配置及迁移

    不得不说微软的技术迭代还是很快的,上了微软的船就得跟着她走下去,前文一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx.superviso ...

  2. .net core 2.0学习笔记(三):度量.net framework 迁移到.net core的工作量

    把现有的.net framework程序迁移到.net core上,是一个非常复杂的工作,特别是一些API在两个平台上还不能同时支持.两个类库的差异性,通过人工很难识别全.好在微软的工程师们考虑到了我 ...

  3. 一起学ASP.NET Core 2.0学习笔记(一): CentOS下 .net core2 sdk nginx、supervisor、mysql环境搭建

    作为.neter,看到.net core 2.0的正式发布,心里是有点小激动的,迫不及待的体验了一把,发现速度确实是快了很多,其中也遇到一些小问题,所以整理了一些学习笔记: 阅读目录 环境说明 安装C ...

  4. .net core 2.0学习笔记(一):开发运行环境搭建

    期待已久的.net core 2.0终于发布了!大家等的花儿都谢了. 不过比预期提前了一个多月,这在微软历史上还真的不多见.按照历史经验看,2.0版本应该比较靠谱,我猜这也是社区非常火爆的原因吧.下面 ...

  5. .net core 2.0学习笔记(五):程序配置&ConfigurationManager

    配置组件是.net framework中非常常用的功能.在创建.net framework 工程时,系统不仅会自动生成app.config文件,而且还提供了非常强大的访问类库.但是这些好东西,在.ne ...

  6. net core 2.0学习笔记(一):开发运行环境搭建 (转)

    期待已久的.net core 2.0终于发布了!大家等的花儿都谢了. 不过比预期提前了一个多月,这在微软历史上还真的不多见.按照历史经验看,2.0版本应该比较靠谱,我猜这也是社区非常火爆的原因吧.下面 ...

  7. dotnet Core 2.0学习笔记(一)

    一:Dotnet Core Windows运行环境,标红部分要注意 https://docs.microsoft.com/en-us/dotnet/core/windows-prerequisites ...

  8. .net core 2.0学习笔记(六):Remoting核心类库RealProxy迁移

    在学习.net core的过程中,我们已经明确被告知,Remoting将不会被支持.官方的解释是,.net framework 类型包含了太多的Runtime的内容,是一个非常重量级的服务实现,已被确 ...

  9. .net core 2.0学习笔记(二):Hello World & 进阶

    官网已经有一个.net core的入手教程(https://www.microsoft.com/net/core#windowscmd),但这个教程完全没有顾及全宇宙第一IDE的感受.今天就跟大家体验 ...

随机推荐

  1. HttpClient以json形式的参数调用http接口并对返回的json数据进行处理(可以带文件)

    1.参数的url就是被调用的地址,map是你要传的参数.参数转成json我使用的是gson方式转换的. 主要使用的jar包有httpclient-4.5.3.jar.httpcore-4.4.6.ja ...

  2. Unreal Engine 4(虚幻UE4)GameplayAbilities 插件入门教程(三)技能标签(Ability Tags)

    本教程参考了https://wiki.unrealengine.com/GameplayAbilities_and_You,如果没有学习前两篇教程,请前往学习. GameplayAbilities插件 ...

  3. gulp-rev-append静态资源添加版本号后缀,清理缓存

    大多用的是gulp-rev.gulp-rev-collerctor两个插件,但过程有点麻烦,使用gulp-rev-append插件轻松搞定 github:   https://github.com/b ...

  4. Spring Boot 系列(五)web开发-Thymeleaf、FreeMarker模板引擎

    前面几篇介绍了返回json数据提供良好的RESTful api,下面我们介绍如何把处理完的数据渲染到页面上. Spring Boot 使用模板引擎 Spring Boot 推荐使用Thymeleaf. ...

  5. 输入三个整数x、y、z,请把这三个数由小到大输出

    题目:输入三个整数x,y,z,请把这三个数由小到大输出. 程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x> y则将x与y的值进行交换,然后再用x与z进行比较,如果x> ...

  6. Chrome浏览器 54 版本显示“Adobe flash player已过期”问题解决

    背景 电脑上面的软件很久没升级,用腾讯电脑管家批量做了一次升级,结果Chrome浏览器升级到54版本flash控件没法用了. 第一时间想到直接到flash官网下载一个新的进行安装,结果官网检测显示,C ...

  7. 机器学习 —— 基础整理(八)循环神经网络的BPTT算法步骤整理;梯度消失与梯度爆炸

    网上有很多Simple RNN的BPTT(Backpropagation through time,随时间反向传播)算法推导.下面用自己的记号整理一下. 我之前有个习惯是用下标表示样本序号,这里不能再 ...

  8. 【PHP】数据类型转换

    PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有: (int).(integer):转换成整形 (float).(double).(real):转换成浮点型 (string):转换成字符串 ...

  9. [Tyvj 1730] 二逼平衡树

    先来一发题面QwQ [TYVJ1730]二逼平衡树 Time Limit:2 s   Memory Limit:512 MB Description 您需要写一种数据结构(可参考题目标题),来维护一个 ...

  10. centos7下安装PHP swoole扩展

    PHP的异步.并行.高性能网络通信引擎,使用纯C语言编写,提供了PHP语言的异步多线程服务器,异步TCP/UDP网络客户端,异步MySQL,异步Redis,数据库连接池,AsyncTask,消息队列, ...