不少.net項目在開發的時候,.net core尚未出現或者還麼有成熟,現在.netcore3.1已經出現,其技術風險已經比較低,今天對項目如何遷移到.net core作一個簡單的梳理,瑾作參考。html
1.免費和最寬鬆的開源協議git
.NET Core從屬於.NET基金會,由微軟進行官方支持。使用最寬鬆的MIT和Apache 2開源協議,文檔協議遵循CC-BY。這將容許任何人任何組織和企業任意處置,包括使用,複製,修改,合併,發表,分發,再受權,或者銷售。惟一的限制是,軟件中必須包含上述版權和許可提示,後者協議將會除了爲用戶提供版權許可以外,還有專利許可,而且受權是免費,無排他性的(任何我的和企業都能得到受權)而且永久不可撤銷,用戶使用.NET Core徹底不用擔憂收費問題,你能夠很自由的部署在任何地方.github
2.輕量級、跨平臺web
3.組件化、模塊化、IOC+Nuget、中間件編程
4.高性能json
5.統一了MVC和WebAPI編程模型windows
a) 好比:ASP.NET Core 中MVC 和Web API 直接或間接繼承同一個基類 ControllerBase,提供可以使用的API也一致化api
b) 好比:舊ASP.NET時代,寫全局filter須要針對MVC 和Web API 分別編寫代碼,但在ASP.NET Core,直接使用一套中間件代碼便可cookie
6.可測試性架構
7.微服務、容器化支持
8.標準化 .NET API 規範- .NET STANDARD,總體架構以下圖:
1.TechEmpower機構
TechEmpower機構會按期對各語言主流的web框架作性能測試
地址:https://www.techempower.com/benchmarks/
2.博客園博主、微軟MVP – 楊曉東,作的 「Hello World」性能測試
ASP.NET Core 1.1性能對比評測(ASP.NET,Python,Java,NodeJS)
地址:https://www.cnblogs.com/savorboard/archive/2016/10/17/dotnet-benchmarks.html
性能測試工具:
微軟出品:Benchmarks
地址:https://github.com/aspnet/benchmarks
度量.net framework 遷移到.net core的工做量
地址:https://www.cnblogs.com/vveiliang/p/7402409.html
可移植性分析工具:.NET Portability Analyzer
地址:https://github.com/Microsoft/dotnet-apiport
【Cli 版本】 【Visual Studio Extension 版本】
地址:https://github.com/Microsoft/dotnet-apiport/tree/dev/docs/VSExtension
評估會給出相似以下報告:
.NET Standard Versions
地址:https://github.com/dotnet/standard/blob/master/docs/versions.md
遷移方案制定
微軟官方《組織項目以支持 .NET Framework 和 .NET Core》文章中,有介紹兩種遷移方案:
方案1、將現有項目和 .NET Core 項目合併爲單個項目(多目標框架)
方案2、將現有項目和新的 .NET Core 項目分離(拷貝到新項目)
遷移過程當中,有類庫命名空間被調整,nuget歸屬包被調整,具體類庫在.NET Core哪一個版本中被實現也不是很清楚,經過下面兩個查詢助手,便可解決這些問題。
一、查詢命名空間、類庫在哪一個nuget package包中定義(第一次查詢比較慢)
地址:https://packagesearch.azurewebsites.net/
二、查詢 NET API 在各版本中實現
地址:https://apisof.net/catalog/
結果圖以下:
類庫項目、應用項目如何選擇框架類型
1.如何組織一個同時面向多目標框架的 C# 項目解決方案
地址:https://walterlv.com/post/organize-csharp-project-targeting-multiple-platforms.html
2..NetStandard;.netCore;FX(.NetFrameWork)之間引用關係
在 .NET Standard 2.0中,咱們使在 .NET Standard 庫中經過一個兼容層去引用已有的 .NET Framework 的庫成爲可能。固然,這隻對那些只使用了適用於 .NET Standard API 的 .NET Framework 庫有效。
FX引用.NetCore:不經過
.NetStandard引用.NetCore:不經過
.NetCore引用FX:經過
.NetCore引用.NetStandard:經過
.NetStandard引用FX:經過
FX引用.NetStandard:經過
ASP.NET Core能夠在「.NET Framework 和 .NET Core」上運行,但ASP.NET Core 3.0 以及更高版本只能在 .NET Core 中運行。
具體參見:
【譯】介紹 .NET Standard
地址:https://www.cnblogs.com/jinanxiaolaohu/p/10681024.html
關於.net core 和 .net fx相互引用的問題
地址:https://q.cnblogs.com/q/103398/
.NetStandard;.netCore;FX(.NetFrameWork)之間引用關係
地址:https://www.cnblogs.com/xiaoliangge/p/7475268.html
3.項目支持多目標框架
支持多目標框架,並解決第三方庫引用差別的問題(在 csproj 文件中指定包含條件)
地址:https://walterlv.com/post/configure-projects-to-target-multiple-platforms.html
目標框架名稱列表 (命名全小寫)
地址:https://docs.microsoft.com/zh-cn/nuget/reference/target-frameworks
如何調試多目標框架類庫?
地址:https://docs.microsoft.com/zh-cn/nuget/reference/target-frameworks
NET Standard/Core項目使用條件判斷輸出多版本xml註釋文檔
地址:https://blog.csdn.net/starfd/article/details/78839704
4.多目標框架中共享代碼方案
一、【首選】.NET Standard,須要目標SDK支持對應的 .NET Standard 版本。
二、共享項目。直接共享了源碼,只要在目標項目中指定了條件編譯符,那麼源碼便能針對各類不一樣的目標框架進行分別編譯。
三、[add as link]使用連接共享 Visual Studio 中的代碼文件
地址:https://blog.csdn.net/starfd/article/details/78839704
5.條件編譯符號 (命名全大寫)
指令:#if #elif #else #endif (||、&&、!)
由於目標框架提供的API不相同。故必要時可添加條件編譯符號以便支持不一樣的運行時版本。
微軟有針對各個目標框架有預約義預處理器符號,vs編譯時會自動識別到這些框架條件編譯符號。
.NET Framework 4.5 --> NET45
.NET Framework 4.6 --> NET46
.NET Framework 4.6.1 --> NET461
.NET Standard 1.0 --> NETSTANDARD1_0
.NET Standard 1.6 --> NETSTANDARD1_6
.NETCOREAPP 2.0 --> NETCOREAPP2_0
參考:
#if指令文檔
地址:https://blog.csdn.net/starfd/article/details/78839704
如何將條件編譯符號(DefineConstants)傳遞給msbuild
地址:http://www.voidcn.com/article/p-nsrcccet-btr.html
使用 Windows 兼容性包將代碼移植到 .NET Core
地址:https://docs.microsoft.com/zh-cn/dotnet/core/porting/windows-compat-pack
如何:將 Windows 窗體桌面應用程序移植到 .NET Core
地址:https://docs.microsoft.com/zh-cn/dotnet/core/porting/winforms
如何:將 WPF 桌面應用移植到 .NET Core
地址:https://docs.microsoft.com/zh-cn/dotnet/core/porting/wpf
遷移HttpHandler與HttpModule到 ASP.NET Core 中間件
地址:https://docs.microsoft.com/en-us/aspnet/core/migration/http-modules?view=aspnetcore-2.2
.NET CORE 2.0 踩坑記錄之ConfigurationManager
地址:https://www.cnblogs.com/binbinxu/p/7440342.html
.NET Core/Standard 2.0 編譯時報「CS0579: Duplicate 'AssemblyFileVersionAttribute' attribute」錯誤
1.自動生成AssemblyInfo的原理
地址:https://www.cnblogs.com/binbinxu/p/7440342.html
2.解決方案:不自動建立 AssemblyInfo 文件
地址:https://cloud.tencent.com/developer/article/1402303
ASP.NET Core開發之HttpContext
地址:https://www.cnblogs.com/linezero/p/6801602.html
.net core 使用JsonConvert替代JavaScriptSerializer
地址:https://my.oschina.net/idoop/blog/915555
ASP.NET Core 中重複讀取 Request.Body 的正確姿式
地址:http://www.cnblogs.com/dudu/p/9190747.html
JsonRequestBehavior在core中被移除的問題
1.[ASP.NET MVC]解決"若要容許 GET請求,請將 JsonRequestBehavior 設置爲AllowGet"
地址:https://shiyousan.com/post/635428880708292949
2.[ASP.NET Core]core中不會拋出AllowGet異常,對於DenyGet則使用[HttpPost]代替
地址:
https://stackoverflow.com/questions/38578463/asp-net-core-the-name-jsonrequestbehavior-does-not-exist-in-the-current-cont
https://stackoverflow.com/questions/8464677/why-is-jsonrequestbehavior-needed?r=SearchResults
獲取ASP.NET Core中的Web根路徑和內容根路徑(移除的MapPath)
地址:http://beidouxun.com/Articles/Details/419f4786-679c-4316-b2bb-baea26c94205
爲何個人會話狀態在ASP.NET Core中不工做了?
地址:https://www.cnblogs.com/lwqlun/p/10526380.html
因爲ASP.NET Core 2.1中引入的Cookie贊成和非必要cookie的GDPR功能引發。(GDPR,即General Data Protection Regulation,《通用數據保護條例》)
在ASP.NET4.5和ASP.NET Core中共享cookies認證信息(加解密方式不一致問題)
.NET跨平臺之旅:ASP.NET Core從傳統ASP.NET的Cookie中讀取用戶登陸信息
地址:https://www.cnblogs.com/cmt/p/5940796.html
開源方案:[git]idunno.CookieSharing
地址:https://github.com/blowdart/idunno.CookieSharing
ASP.NET Core如何獲取客戶端IP地址(被移除的ServerVariables對象)
地址:https://www.cnblogs.com/dudu/p/5972649.html
如何獲取項目依賴的全部程序集
方案一:AppDomain.CurrentDomain.GetAssemblies(),此辦法不能獲取到全部依賴的程序集,由於.Net有延遲加載程序集機制
方案二:適用於傳統ASP.NET項目,System.Web.Compilation.BuildManager.GetReferencedAssemblies();
方案三:適用於ASP.NET Core項目,DependencyContext.Default.CompileLibraries,具體代碼參考下面
參考:
AppDomain.CurrentDomain.GetAssemblies()
地址:https://www.cnblogs.com/beixing/p/3803874.html
Is there an alternative for BuildManager.GetReferencedAssemblies() in ASP.NET Core?
地址:https://stackoverflow.com/questions/53989393/is-there-an-alternative-for-buildmanager-getreferencedassemblies-in-asp-net-co
.NET Core 2.0遷移System.Runtime.Caching
地址:https://www.cnblogs.com/mantgh/p/7429551.html
.NET Core 2.0升級到3.0實戰方案
地址:https://www.cnblogs.com/laozhang-is-phi/p/11520048.html
從.NET CORE2.2升級到3.0過程及遇到的一些問題
地址:https://www.cnblogs.com/roadflow/p/11711686.html
【微軟官方】從 EF6 到 EF Core的遷移系列
地址:https://www.cnblogs.com/roadflow/p/11711686.html
【微軟官方】EF Core 版本升級遷移系列
地址:https://docs.microsoft.com/zh-cn/ef/core/what-is-new/ef-core-2.2
按照上面的方式修改API兼容性後,框架類庫能夠順利遷移到.NET Core,編譯經過,代碼運行也正常。可是ASP.NET Core風格的應用,其寫法也是有不少變化的。具體參考下面文檔:
將傳統 ASP.NET 應用遷移到 .NET Core
地址:https://mp.weixin.qq.com/s?__biz=MzAwNTMxMzg1MA==&mid=2654072516&idx=3&sn=af3916ec4e2c31c231f5f01be75712d8&chksm=80dbca91b7ac43870a3fa4dce10f5a97adf1548d1381a99f27972c67c00a1e593aa926b110ad&mpshare=1&scene=23&srcid=0311kxbJ5rwkIYu7xO2Yx08U
【微軟官方】ASP.NET 遷移到 ASP.NET Core教程系列
地址:https://docs.microsoft.com/zh-cn/aspnet/core/migration/proper-to-2x/?view=aspnetcore-2.2
【微軟官方】ASP.NET Core 版本升級遷移系列
地址:https://docs.microsoft.com/zh-cn/aspnet/core/migration/20_21?view=aspnetcore-2.2
相關文章:
.NET Core 3中的性能提高(譯文)
地址:https://zhuanlan.zhihu.com/p/66152703
Java(11,12) 與 .NET Core(2.2,3.0)的性能對比測試
地址:https://blog.csdn.net/hez2010/article/details/86551299
載自:cnblog.windy