迁移.net framework 工程到.net core
在遷移.net core的過程中,第一步就是要把.net framework 工程的目標(biāo)框架改為.net core2.0,但是官網(wǎng)卻沒有提供轉(zhuǎn)換工具,需要我們自己動手完成了。.net framework 工程遷移為.net core工程大體上有兩種方案:
???? 1.創(chuàng)建一個.net core的工程,然后把所有的文件挪過去。這是比較笨的一種辦法,如果工程比較小,還好弄。如果有幾百工程,那就哭了。
???? 2.通過編輯.csproj文件,強制把工程遷移到.net core下。
???? 今天給大家分享的就是,如何通過修改.csproj文件的方式,把.net framework 工程遷移到.net core下。
???? 步驟一:通過VS2017打開.net framework 解決方案,卸載指定的項目后,打開.csproj文件。
???? 步驟二:移除兩個 import引用
??? 步驟三:移除 Release、Debug編譯的配置信息
???? 步驟四:修改 Project節(jié)點屬性:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
???? 替換為:
<Project Sdk="Microsoft.NET.Sdk">
???? 步驟五:移除TargetFrameworkVersion信息,增加信息:<TargetFramework>netcoreapp2.0</TargetFramework>
???? 步驟六:重新加載項目
???? 步驟七:在已經(jīng)加載的 .net core項目上,繼續(xù)編輯csproj文件。
???? 步驟八:移除文件列表信息。
???? 步驟九:移除AssemblyInfo.cs文件。
???? 步驟十:移除.net framework工程中隱藏的文件。因為.net core 工程不支持排除文件,所以在完成上述遷移后,原來隱藏的文件會自動添加到工程中,對這些垃圾文件,請識別后,手工刪除即可。
???? 步驟十一:重新添加nuget包引用。.net framework 對nuget包的引用信息是存儲到packages.config中的。此文件已經(jīng)在.net core中移除。請根據(jù)packages.config信息,在項目中重新添加nuget引用。引用信息將會自動添加到csproj文件中。
???? 步驟十二:編譯工程。說一下,很多.net framework的API在.net core中已經(jīng)沒有了,正在遷移前,請看一下下面的.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. 不支持相關(guān)配置對象:
??? * ConfigurationManager
??? * WebConfigurationManager
??? * ConfigurationSection
14. 不支持繪圖
??? * System.Drawing
??? * System.Drawing.Size
15. 無法使用相關(guān)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,無法識別是否響應(yīng)加了GZip,也或許能自動識別
??? * 不支持:httpWebRequest.Referer / .UserAgent 無法設(shè)置請求瀏覽器和來源地址
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
相關(guān)文章:?
.NET應(yīng)用遷移到.NET Core(一)
.NET應(yīng)用遷移到.NET Core(二)風(fēng)險評估
.NET應(yīng)用遷移到.NET Core(三)從商業(yè)角度看移植過程
.NET應(yīng)用遷移到.NET Core--調(diào)查案例
遷移傳統(tǒng).net 應(yīng)用到.net core [視頻]
應(yīng)用工具 .NET Portability Analyzer 分析遷移dotnet core
.net core 2.0學(xué)習(xí)筆記(一):開發(fā)運行環(huán)境搭建
.net core 2.0學(xué)習(xí)筆記(二):Hello World & 進階
度量.net framework 遷移到.net core的工作量
原文地址:?http://www.cnblogs.com/vveiliang/p/7409825.html
.NET社區(qū)新聞,深度好文,微信中搜索dotNET跨平臺或掃描二維碼關(guān)注
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的迁移.net framework 工程到.net core的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Orleans稍微复杂的例子—互动
- 下一篇: Entity Framework Cor