.NET Core
How to migrate and write new code for .NET Core
Bertrand Le Roy
▪ Senior Program Manager on .NET Core
▪ One of the founders of Orchard
▪ http://weblogs.asp.net/bleroy
▪ https://blogs.msdn.microsoft.com/dotnet/tag/week-in-net/
▪ https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw
Objectives
▪ What’s .NET Core and when to use it (or not)
▪ How to create a new library, ASP.NET, or console application
▪ How to port existing code
Innovation Any platformOpenness
.NET Core
ASP.NET 5
.NET Core ≠ .NET Framework
.NET Framework 4.6
▪ .NET implementation for any scenario on Windows with comprehensive library
support
.NET Core
▪ Modular and smaller implementation of .NET
▪ Cross-platform
▪ App-level isolation
▪ Built in the open
▪ Optimized for specific workloads
▪ Built for the next ten years of software development
Next gen JIT (RyuJIT)
SIMD
Runtime
Components Compilers
Languages innovation
.NET Compiler Platform
.NET Core 5 Libraries
.NET Framework 4.6 Libraries
NuGet packages
.NET Framework 4.6 .NET Core
What’s common, and what’s not?
What’s not supported?
▪ WPF
▪ Winforms
▪ WebForms
▪ Binary serialization…
▪ Anything Windows-specific: registry, ACLs, perf counters, etc.
Significant change: Reflection
foo.GetType() → foo.GetType().GetTypeInfo()
API Portability resources
▪ Portability analyzer VS extension
▪ https://github.com/Microsoft/dotnet-apiport/releases
▪ http://dotnetstatus.azurewebsites.net/
▪ https://packagesearch.azurewebsites.net/
▪ http://forums.dotnetfoundation.org/
▪ https://gitter.im/dotnet/corefx
▪ https://dotnet.github.io/porting *
Managing expectations
▪ This is very much a new platform with a known flavor
▪ There is a cost to migration
▪ There are things to learn
▪ Not all projects can or should migrate
Should I migrate my project?
Cannot:
▪ WPF, WinForms, unless UWP
▪ ASP.NET WebForms
Should (absolutely):
▪ General purpose libraries
Should (maybe):
▪ ASP.NET MVC
▪ Micro-services
▪ Console apps
▪ Rewrite
▪ Talent expertise on Linux
DEMO
Porting FluentPath
Dependencies
▪ Most fundamental libraries first: test frameworks, tooling, data access, JSON,
logging, IoC, etc.
▪ Go to the source, ask the author
▪ Offer to help, or fork
▪ Switch to another Core-compatible library
▪ DIY
Testing
▪ xUnit was first, now NUnit, MsTest
▪ Secondary test libraries (mocking, functional testing, etc.) in progress
Debugging
▪ On Windows: Visual Studio
▪ Everywhere: VS Code
Tooling
Your choice of tool, on your choice platform
▪ Visual Studio on Windows
▪ Visual Studio Code on Mac, Linux, or Windows
▪ vi or emacs with OmniSharp
▪ etc.
.NET CLI replaces DNX, DNVM, DNU
▪ dotnet new
▪ dotnet restore
▪ dotnet run
▪ dotnet build
▪ dotnet build –native
▪ dotnet dosomethingcool
DEMO
Creating a new application
Q&A

.Net Core

  • 1.
    .NET Core How tomigrate and write new code for .NET Core
  • 2.
    Bertrand Le Roy ▪Senior Program Manager on .NET Core ▪ One of the founders of Orchard ▪ http://weblogs.asp.net/bleroy ▪ https://blogs.msdn.microsoft.com/dotnet/tag/week-in-net/ ▪ https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw
  • 3.
    Objectives ▪ What’s .NETCore and when to use it (or not) ▪ How to create a new library, ASP.NET, or console application ▪ How to port existing code
  • 4.
  • 5.
    .NET Core ≠.NET Framework
  • 6.
    .NET Framework 4.6 ▪.NET implementation for any scenario on Windows with comprehensive library support
  • 7.
    .NET Core ▪ Modularand smaller implementation of .NET ▪ Cross-platform ▪ App-level isolation ▪ Built in the open ▪ Optimized for specific workloads ▪ Built for the next ten years of software development
  • 8.
    Next gen JIT(RyuJIT) SIMD Runtime Components Compilers Languages innovation .NET Compiler Platform .NET Core 5 Libraries .NET Framework 4.6 Libraries NuGet packages .NET Framework 4.6 .NET Core What’s common, and what’s not?
  • 9.
    What’s not supported? ▪WPF ▪ Winforms ▪ WebForms ▪ Binary serialization… ▪ Anything Windows-specific: registry, ACLs, perf counters, etc.
  • 10.
    Significant change: Reflection foo.GetType()→ foo.GetType().GetTypeInfo()
  • 11.
    API Portability resources ▪Portability analyzer VS extension ▪ https://github.com/Microsoft/dotnet-apiport/releases ▪ http://dotnetstatus.azurewebsites.net/ ▪ https://packagesearch.azurewebsites.net/ ▪ http://forums.dotnetfoundation.org/ ▪ https://gitter.im/dotnet/corefx ▪ https://dotnet.github.io/porting *
  • 12.
    Managing expectations ▪ Thisis very much a new platform with a known flavor ▪ There is a cost to migration ▪ There are things to learn ▪ Not all projects can or should migrate
  • 13.
    Should I migratemy project? Cannot: ▪ WPF, WinForms, unless UWP ▪ ASP.NET WebForms Should (absolutely): ▪ General purpose libraries Should (maybe): ▪ ASP.NET MVC ▪ Micro-services ▪ Console apps ▪ Rewrite ▪ Talent expertise on Linux
  • 14.
  • 15.
    Dependencies ▪ Most fundamentallibraries first: test frameworks, tooling, data access, JSON, logging, IoC, etc. ▪ Go to the source, ask the author ▪ Offer to help, or fork ▪ Switch to another Core-compatible library ▪ DIY
  • 16.
    Testing ▪ xUnit wasfirst, now NUnit, MsTest ▪ Secondary test libraries (mocking, functional testing, etc.) in progress
  • 17.
    Debugging ▪ On Windows:Visual Studio ▪ Everywhere: VS Code
  • 18.
    Tooling Your choice oftool, on your choice platform ▪ Visual Studio on Windows ▪ Visual Studio Code on Mac, Linux, or Windows ▪ vi or emacs with OmniSharp ▪ etc.
  • 19.
    .NET CLI replacesDNX, DNVM, DNU ▪ dotnet new ▪ dotnet restore ▪ dotnet run ▪ dotnet build ▪ dotnet build –native ▪ dotnet dosomethingcool
  • 20.
  • 21.

Editor's Notes

  • #5 Innovation: Innovate and deliver much faster Prompt audience about their favorite pas innovation from .NET. Quote Roslyn, Linq, async/await, generic implementation. Openness enriches the platform and the community On any device and platform
  • #6 Core is different from .NET Framework, and Core is also not .NET Fx 5.
  • #8 Open: not just the source: design documents, code reviews, experiments, roadmaps Open contributions with quality standards, in particular in terms of security.
  • #10 Windows-specific: at least for now, as platform-specific libraries will appear.
  • #15 WPF, WinForms, even if the application isn’t going cross-platform, stay on .Net Fx. A migration to UWP is possible, but that means a rewrite of the UI in addition to the Core migration. ASP.NET WebForms applications should remain on .NET Fx. On the other hand, MVC applications, micro-services, console apps, and anything that can benefit in being deployed cross-platform, especially using containers, is an excellent choice. General purpose libraries should definitely be ported and support both Core and Fx.
  • #16 Open VS, go to Tools / Extensions and updates, show the portability analyzer is there. Open FluentPath solution, right-click Fluent.IO, analyze/analyze portability -> 100% Do the same on Fluent.IO.Windows -> 91.67%, and a detailed list of failures. Those APIs are simply not supported because Windows-specific. Do the same with the NonPortableLibrary solution -> 97.22%. Show how the IsAbstract recommended change is to go through GetTypeInfo(). Show the html file on disk. From the NonPortableLibrary root folder, do …\apiport.exe listOutputFormats; …\apiport.exe analyze –f .\bin\Debug –r Excel –o report.xlsx. Show the Excel report with its two tabs. Go to http://dotnetstatus.azurewebsites.net, look for IsAbstract, show the Type and TypeInfo entries. (That’s an anomaly due to the fact that TypeInfo on .NET Framework derives from Type. Most of the TypeInfo thus show up as defined by the base.) Go to https://packagesearch.azurewebsites.net, look for IsAbstract, show the result for System.Reflection.TypeInfo, show package name and version number.
  • #17 Open the Nuget Package Explorer.+3. Click "Open a package from online feed". (screenshot)+4. Search for the name of a package in the search field and hit enter. (screenshot of result)+5. Expand the "lib" folder and look for a target subfolder that is compatible with .NET Core. (screenshot)++ TODO: Something with `dnxcore50`, `dotnet`, `netstandardlib`, ... is what you're looking for.+ + If there isn't a target subfolder compatible with .NET Core, the dependency will not run on .NET Core.
  • #20 Mention JetBrains Project Rider
  • #21 Dotnet build, in the case of an app, generates runnable assets by copying an executable host.
  • #22 Create new portable library from VS by following the script http://aka.ms/port2core Create new command-line app from CLI: show https://github.com/dotnet/cli/blob/master/Documentation/intro-to-cli.md