16年專案資歷
4年顧問資歷
• 部落格 (Gelis 技術隨筆)
http://gelis-dotnet.blogspot.tw/
• FB 粉絲團(Gelis 的程式設計訓練營)
https://www.facebook.com/gelis.dev.learning/?ref=bookmarks
• FB 社團 (軟體開發之路)
https://www.facebook.com/groups/361804473860062/?ref=ts&fref=ts
集英信誠 - 資深.NET開發顧問
.NET Conf
什麼是 .NET Standard?
• .NET Standard
.net 程式庫 BCL (Base Class Library) 並取
代現有的可攜式類別庫 PCLs.
所以目標是希望開發人員不會因為這(Full .NET Framework
/.NET Core/Xamarin)三個平台就要改寫 .NET 程式碼
.NET BCL (Base Class Library) .NET
Standard
• 因此沒有良好系統(APIs)版本控制方法
• 不容易計算出各 Platform 交叉之處
• 若再有新平台出現,便不相容
• 不容易維護其 PlatForm 間相容的關係
Platform 3Platform 1
Platform 2
Platform 4
?
今天的 .NET —reusing code
今天的 .NET —reusing code
今天的 .NET —reusing code
.NET tomorrow
.NET Standard
BASE
LIBRARIES
.NET tomorrow
.NET Standard
.NET tomorrow
.NET Standard
容易
容易
容易
.NET Standard 2.0+
 支援更多的 APIs!  與 .NET Framework libraries 完全兼容
 .NET standard 2.0 的 APIs 數
量幾乎是 1.6 的一倍之多!
大部分的 APIs 仍舊與現有 .NET
Framework 完全相容
因為相容性的因素,您依舊可以
在其他平台上使用
Version #APIs Growth %
1.6 13,501 +1%
2.0 32,638 +142%
Target Usage on NuGet
.NET Framework 46,894
.NET Standard 1,886
PCL 4,501
~70%
+20K
• .NET Framework 4.6.1
• .NET Core 2.0 ↑
• Xamarin.Android 8.0
Primitives • Collections • Reflection • Interop • LinqCORE
Threads • Thread Pool • TasksTHREADING
Files • Compression • MMFIO
Sockets • Http • Mail • WebSocketsNETWORKING
BinaryFormatter • Data Contract • XMLSERIALIZATION
XLinq • XML Document • XPath • Schema • XSLXML
Abstractions • Provider Model • DataSetDATA
• 外圍的可以包含內圈所有項目
各自實現了一
部份的 .NET Standard 標準
• 也就是說,在目前的 .NET
Standard 2.0+ 中,您可以參考
1.6/1.3/1.0 的 DLLs
2.0+
1.6
1.3
1.0
.NET Standard 那『目標』的 .NET
Framework 版本是 4.6.1 以上?
2.x
4.6.2 4.7.x (只會提升)
Immo Landwerth 提供的 .NET Standard 互動式資料表
How does .NET Standard work?
NetStandard.Library
netstandard.dll
netstandard.dll
My Standard Library 2.x
.NET Standard Library .NET Framework LibraryPortable Class Library
.NET FRAMEWORK .NET CORE XAMARIN
Via Portability
Via Compatibility Shim
Legend
Application Type
Is able to reference
TYPE
FORWARDING
This happens when you build a .NET Standard-based Library
TYPE
FORWARDING
This happens when you load .NET Standard-based library
TYPE
FORWARDING
This happens when you build a .NET Standard-based library with platform-specific extensions
TYPE
FORWARDING
This happens when you load .NET Standard-based library with platform-specific extensions
EXCEPTION
TYPE
FORWARDING
什麼是 Type Forwarding?
這是什麼黑魔法?
而無須重新編譯
使用該組件的原應用程式
• 在需要尋找該型別的來源組件加入 TypeForwardAttribute:
• [assembly: TypeForwardToAttribute(typeof(ExampleClass))]
• 原本參照的程式碼中原本的 using 與使用部分都不需要修改
• 因為應用程式只需要與 netstandard.dll 耦合
• 其實就是 Proxy Pattern 樣式
• TypeForwardToAttribute 定義在:System.Runtime.CompilerService
• 使用命令列編譯 C# 時,使用 /reference 編譯器選項
«元件»
«元件»
Class1
TypeForwardToAttribute(typeof(Class1))
型別轉送
使用.NET Portability Analyzer
檢測現有程式碼不支援那些平台?
https://marketplace.visualstudio.com/items?itemName=ConnieYau.NETPortabilit
yAnalyzer
https://github.com/Microsoft/dotnet-apiport/releases?id=42678
Lower Version
More Reach
Higher Version
More APIs
HTTP/HTTPS
Business Object
Business Object
Web Host
JSON Over
(Web API/SignalR)
ApiHostBase
ApiCore ServerComponent
fb.com/Study4.twfb.com/groups/216312591822635 Study4.TW
Q & A
謝謝大家!

使用 .NET Standard 開發跨平台應用程式

Editor's Notes

  • #12 Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries. Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
  • #13 Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries. Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
  • #14 Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries. Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
  • #15 Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries. Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
  • #16 Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries. Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.
  • #17 Notes: Even if we are reusing a lot across components (especially with the open sourcing last year), the reality is that each platform has its own implementation of the base libraries. Note: .NET Framework BCL and Mono BCL are the same APIs, different implementation. .NET Core “Core Library” is a similar set of APIs, but different.