在迁移.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应用迁移到.NET Core(一)

  • .NET应用迁移到.NET Core(二)风险评估

  • .NET应用迁移到.NET Core(三)从商业角度看移植过程

  • .NET应用迁移到.NET Core--调查案例

  • 迁移传统.net 应用到.net core [视频]

  • 应用工具 .NET Portability Analyzer 分析迁移dotnet core

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

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

  • 度量.net framework 迁移到.net core的工作量

原文地址: http://www.cnblogs.com/vveiliang/p/7409825.html


.NET社区新闻,深度好文,微信中搜索dotNET跨平台或扫描二维码关注

迁移.net framework 工程到.net core相关推荐

  1. 如何移植.NET Framework项目至.NET Core?

    公司的项目一直采用.NET框架来开发Web项目.目前基础类库均为.NET Framework 4.6.2版本.Caching, Logging,DependencyInjection,Configur ...

  2. 《你必须掌握的Entity Framework 6.x与Core 2.0》书籍出版

    前言 到目前为止写过刚好两百来篇博客,看过我博客的读者应该大概知道我每一篇博客都沿袭着一贯的套路,从前言到话题最终到总结,本文依然是一如既往的套路,但是不是介绍技术,也可说是介绍技术,不过是介绍书中的 ...

  3. 《你必须掌握的Entity Framework 6.x与Core 2.0》正式出版感想

    前言 借书正式出版之际,完整回顾下从写博客到写书整个历程,也算是对自己近三年在技术上的一个总结,整个历程可通过三个万万没想到来概括,请耐心阅读. 写博.写书完整历程回顾 从2013年12月注册博客园账 ...

  4. 从文本分类问题中的特征词选择算法追踪如何将数学知识,数学理论迁移到实际工程中去...

    博文转载请注明作者和出处(作者:finallyliuyu :出处博客园) 附:<卡方特征词选择算法> <DF特征词选择算法> 一.数学背景 将数学知识.数学理论以及数学思想迁移 ...

  5. Git服务器所有项目代码迁移,Gitlab代码工程迁移

    由于项目需要,有时可能需要将代码工程从一个gitlab服务器迁移至另一个gitlab服务器.下面介绍三种迁移的方式. 方案一:直接在gitlab界面上import 该方法是在gitlab网页上一个一个 ...

  6. Orchard Core Framework:ASP.NET Core 模块化,多租户框架

    上一篇编写Orchard Core一分钟搭建ASP.NET Core CMS ,介绍ASP.NET Core CMS ,Orchard的ASP.NET Core版,同时对应有一个ASP.NET Cor ...

  7. 迁移传统.net 应用到.net core [视频]

    .net core是.NET技术的未来,这一点正在被越来越多的公司认识到,但是如何将传统的.NET应用迁移到.NET Core是一个迫切需要解决的问题.对于传统.NET应用来说,使用和不使用.NET ...

  8. asp.net Framework 与 asp.net core 知识

    .NET Compiler Platform ("Roslyn") .NET编译器.提供的开源Csharp和Visual Basic编译器及代码解析API .NET Core Fr ...

  9. .NET Framework 工程Target framework配置问题

    我在写程序的时候,为了实现窗口拖拽和附边的功能,引用了WinFormsUI的包,当我Form继承自里面的控件DockContent时,会出现这样的错误 这样的错误,在修改了 Project->P ...

最新文章

  1. 关于介绍编程前景的html文档,HTML编程基础稿件(32页)-原创力文档
  2. redis 一主二从
  3. 强化学习笔记: generalized policy iteration with MC
  4. C++使用类静态成员跟踪对象的个数
  5. C++静态全局变量问题
  6. 【渝粤题库】国家开放大学2021春2786初级西方经济学题目
  7. springboot项目中使用shiro 自定义过滤器和token的方式___shiro使用token登录流程
  8. 第七:Pytes中的fixture大解剖(一)
  9. ComponentArt Web.UI控件的bug及解决办法
  10. 推荐一款免费开源的javascript电子表格:x-sheet
  11. xprinter打印机android 开发文档,芯烨智能打印机,让手机功能更神奇
  12. 如何判断股市能否持续上涨?
  13. 基于Mybatis的语音播报随机点到系统
  14. map和set的异同
  15. 计算机服务器加载失败,win10系统打开windows Media player听歌提示“服务器运行失败”的详细步骤...
  16. ECharts 饼图数据放在饼图内部显示
  17. session取不到的原因_游戏id不会取?来看看职业选手是如何取id的!满满的干货哦。...
  18. 【干货书】分布式算法
  19. GreenDao 使用详解(入门篇)
  20. 工具:Excel使用指南

热门文章

  1. 长江存储年底提供自研32层堆叠3D NAND闪存样品
  2. #HTTP协议学习# (七)cookie
  3. 关于F5 排错的简单介绍之一
  4. iPhone Development Blog系列: 如何制作服务条例窗口
  5. 如何有效的在 LINQ 查询中处理异常?
  6. CALL FOR DUTY 来和我们一起冒险吧!
  7. C# 修改配置文件进行窗体logo切换
  8. Dapr牵手.NET学习笔记:用docker-compose部署服务
  9. C#多线程开发-任务并行库
  10. .NET Core 中有等价的 HttpContext.Response.Cache 吗?