.NET Core改造工程直播

[背景]

新项目需要跨平台,原来积累的.NET类库需要改造为.NET Core。

[直播]

  1. 新增加的项目不支持排除文件
  2. 不支持定义条件编译常量,虽然在项目中能使用#if语法,但无地方定义DefineConstants
  3. 使用nuget时,不能区分哪些可以引用,只有强制引用时会报出异常 error: Package xxx is not compatible with netstandard1.6
  4. 不支持序列化和xml操作
    1. (需要:Install-Package System.Xml.XmlDocument , Install-Package System.Runtime.Serialization.Formatters -Pre, Install-Package System.Xml.XmlSerializer)
    2. XmlDocument
    3. XmlIgnore
    4. Serializable
    5. XmlNode
    6. BinaryFormatter
    7. SoapFormatter
    8. InflaterInputStream
    9. DataContractSerializer (Install-Package System.Runtime.Serialization.Xml)
    10. DataContractJsonSerializer(Install-Package System.Runtime.Serialization.Json)
  5. 部分反射需要改造
    1. 比如Type.GetProperties()要改为Type.GetTypeInfo().GetProperties()
    2. 不支持Assembly.GetExecutingAssembly() https://forums.asp.net/t/2001385.aspx
  6. 不支持部分对象:
    1. ArrayList
    2. Hashtable
    3. HybridDictionary
    4. BindingList
    5. Thread(Install-Package System.Threading.Thread)
    6. Process(Install-Package System.Diagnostics.Process)
    7. HttpContext
    8. AppDomain
    9. DataSet / DataTable / DBNull
  7. 注册表无法访问
    1. RegistryKey
  8. 不支持nHibernate,nHibernate尚未升级支持Core
  9. 不支持log4net
  10. 不支持相关配置对象:
    1. ConfigurationManager
    2. WebConfigurationManager
    3. ConfigurationSection
  11. 不支持绘图
    1. System.Drawing
    2. System.Drawing.Size
  12. 无法使用相关Web对象
    1. System.Web.HttpUtility.HtmlDecode
  13. 很多Stream没有了Close()方法,直接替换为Dispose()
  14. DateTime.Now.ToShortDateString() 替换为 DateTime.Now.ToString("yyyy-MM-dd")
  15. 不支持部分Attribute
    1. DescriptionAttribute
  16. WebResponse/WebRequest对象有变化
    1. 不支持:httpWebResponse.ContentEncoding,无法识别是否响应加了GZip,也或许能自动识别
    2. 不支持:httpWebRequest.Referer / .UserAgent 无法设置请求浏览器和来源地址


[感受]

    1. Core的改造工作不是那么容易。要是有转换工具就好了。
    2. 或是原有的工程不用改造,在Linux中使用Docker技术来模拟.net需要的环境就好了;
    3. 原有的项目的特性未保留下来,比如:排除部分文件,添加链接文件;

 

posted on 2016-10-10 16:24  DecleorMX  阅读(541)  评论(0编辑  收藏  举报

导航