.Net Core Blimey! (16/07/2015)

35
.NET Core Blimey. @citizenmatt

Transcript of .Net Core Blimey! (16/07/2015)

Page 1: .Net Core Blimey! (16/07/2015)

.NET CoreBlimey.

@citizenmatt

Page 2: .Net Core Blimey! (16/07/2015)

This is Matt Ellis

He works for Microsoft, and is a developer on the .NET Core team.

This is not me.

Page 3: .Net Core Blimey! (16/07/2015)

This is Matt Ellis

He works for JetBrains, and is an interested amateur in .NET Core.

This is me.

Page 4: .Net Core Blimey! (16/07/2015)

What is .NET Core?

New .NET stack - CLR + BCL

Open SourceCross platform

(eventually)Standalone -

per-application installs

Factored for modularity - “cloud optimised”

Everything ships as NuGet packages,

including the runtime

Not finished…

Page 5: .Net Core Blimey! (16/07/2015)

.NET Core != .NET Framework

NOT a new version of the .NET Framework

• .NET Framework is going nowhere

• .NET Core is 5.0.NET Framework is 4.6

• .NET Core is a fork of the .NET Framework Code merged back to TFS

• .NET Core is (currently) a strict subset of the .NET Framework

• Missing pieces in .NET CoreWindows: WinForms, WPF, COM, etc.Platform: AppDomains, Remoting, Reflection.Emit, etc.

• Different constraints:Ship cycles, compatibility, system wide install

Page 6: .Net Core Blimey! (16/07/2015)

Why?

Multiple .NET stacks. Incompatibilities

Portable Class Librariesnot scalable

Cross platform

Independent release cyclesRuntime, BCL, apps

Nano Server

Tidy up15 years of evolution

Page 7: .Net Core Blimey! (16/07/2015)

History

Started with .NET Framework 2.0

Page 8: .Net Core Blimey! (16/07/2015)

How do I get it?

DNX - Dot Net Execution Environment

Maintained by asp.net team

Stable builds on nuget.orgUnstable on myget.org

.NET Core team maintain own build

dnvm install latest -r coreclr -u

Page 9: .Net Core Blimey! (16/07/2015)

Build from source!

How do I get it?

Page 10: .Net Core Blimey! (16/07/2015)

Architecture

Boxes and bits.

Page 11: .Net Core Blimey! (16/07/2015)

.NET Native

Alternative runtime

• AOT compilation

• Compiles all dependenciesTree shaking

• Reflection? Via xml!

• Windows Store apps only

• Closed source

• On hold

• LLILC - LLVM based JIT/AOT (OSS)

Page 12: .Net Core Blimey! (16/07/2015)

CoreCLR The new runtime.

Page 13: .Net Core Blimey! (16/07/2015)

dotnet/coreclr

JIT compiler (RyuJIT), Garbage Collector, Platform Abstraction Layer - C++

mscorlib (tightly coupled to runtime) - C#

PAL - OS and platform differences. E.g. exception handling, threads, etc.P/Invoke to OS, FEATURE #ifdefs

Book of the Runtime!

Mirror back to TFS

Page 14: .Net Core Blimey! (16/07/2015)

CoreFX The new BCL.

Page 15: .Net Core Blimey! (16/07/2015)

dotnet/corefx

Factored for modularity - each solution/assembly is a package

Some platform specific implementations, e.g. System.Console, Process.Interop.Unix.cs, etc.

Might throw PlatformNotSupportedException(e.g. Console.get_ForegroundColor )

Build is based on project.json, packages as references

Mirrored to TFS + .NET Framework

High compatibility bar for changes, transparent API review process

Console.get_ForeoundColorPlatformNotSupportedException

Page 16: .Net Core Blimey! (16/07/2015)

AppModels

Or: How do you run a .exe on Unix?

Page 17: .Net Core Blimey! (16/07/2015)

How the application is hosted and run

Environmental services

What is an AppModel?

Bootstrap the CLR Execute the application

Page 18: .Net Core Blimey! (16/07/2015)

.NET Framework AppModels

.NET .exe

Originally a native stub that loaded the CLR (x86 only!)

Special cased by OS loader since Windows XP

Loads mscoree.dll, which initialises CLR and executes

app

IIS/asp.net

Pre-IIS 7 - ISAPI filter

IIS 7 directly integrates CLR

Pipes requests/responses to managed code

Lifetime management

Windows Phone / Windows Store

Magic!

“Application host” loads CLR

Integrates with environment events. E.g. suspend and

resume applications

Pre-compiled / .NET Native

Page 19: .Net Core Blimey! (16/07/2015)

corerun

DNX - .NET Execution Environment (asp.net)

Windows 10 UWP Applications

.NET Core AppModels

coreconsole /osxcorebundlerun

Page 20: .Net Core Blimey! (16/07/2015)

DNX

Dot NET Execution Environment

asp.net 5Targets .NET Core /.NET Framework /

Mono

In memory compilation via Roslyn

Changes project systemReference packages, not assemblies

More…

Page 21: .Net Core Blimey! (16/07/2015)

• Packages for runtime and BCL

• BCL factored into many packages

• NuGet at heart of project system (DNX)

• NuGet is the new Portable Class Library

• Changing daily. Undocumented…

NuGet

Bleeding edge.

Page 22: .Net Core Blimey! (16/07/2015)

How does this affect us?

Let NuGet be NuGet

Don’t target a framework

Add NuGet dependencies for all BCL assemblies

Specify required versions of BCL assemblies

Let NuGet sort it out

Effectively, there is no longer a fixed framework

version to target

Page 23: .Net Core Blimey! (16/07/2015)

New Target Framework Monikers

Brand new

• dotnet - - .NET Core contracts. Use this!

• dnx451 , dnx46 - DNX targeting .NET Framework 4.5.1, 4.6

• dnxcore50 - DNX targeting .NET Core

• netcore50 - .NET Core 5.0 on Windows (UWP apps. Follows netcore45 / win8 , netcore451 / win81)

dotnet

dnx451 dnx46

dnxcore50

netcore50netcore45 win8 netcore451 win81

Page 24: .Net Core Blimey! (16/07/2015)

What About Compatibility?

All .NET Core packages are PCLs. Kinda.

Page 25: .Net Core Blimey! (16/07/2015)

PCL Refresher

1. A PCL is a class library that needs to run on multiple platforms and versions(e.g. .NET Framework, Windows Phone, Xamarin)

2. It defines a common subset of APIs that are available on ALL of the required versions of these platforms - a “Profile”

3. When targeting a Profile, the compiler references a set of Reference AssembliesThese describe the API with empty types, and forward types to correct assemblies

4. At runtime, the real assemblies on the target platform implement the APIs Can also forward types to other assemblies

Page 26: .Net Core Blimey! (16/07/2015)

Portable Class Libraries

• PCL hides platform specific implementation details behind a common API contract

• Profiles do not scale. The more versions and platforms, the more Profiles…

Page 27: .Net Core Blimey! (16/07/2015)

Why is this important?

Isn’t .NET Core a common, compatible, cross platform implementation?

• The BCL is the Base Class Library. It’s low level, and has to worry about underlying platform differences, e.g. file IO

• The BCL needs to be abstracted away from the platform, to allow for platform specific implementations. And refactoring!

Page 28: .Net Core Blimey! (16/07/2015)

Reference Assemblies

BCL packages include a Reference Assembly in \ref

• This is referenced at compile time and provides the contract for the API, just like PCL Reference Assemblies

• The runtime implementation(e.g. \lib\netcore50 ) handles platform/host specifics

\ref

\lib\dnxcore50

Page 29: .Net Core Blimey! (16/07/2015)

Why is this important?

This is how compatibility works

• Reference Assemblies allow consuming .NET Core packages from .NET Framework and other PCL platforms

• Reference Assembly provides the contract, forwards any types

• Implementation assemblies provide potential platform specific implementations

Page 30: .Net Core Blimey! (16/07/2015)

Compatibility (not a guarantee)

• .NET Framework 4.6 can consume .NET Core packages • .NET Core 5.0 is a subset of .NET Framework 4.6

Should be able to consume .NET Framework 4.6 packages • .NET Core can consume PCL libs that are compatible with System.Runtime.dll

(facade that forwards to e.g. mscorlib.dll) • A new PCL Profile will include .NET Core (e.g. ) portable-dotnet+…+…

Page 31: .Net Core Blimey! (16/07/2015)

Known Unknowns

• How are OS specific implementations going to be shipped?

• Do we need a Reference Assembly for each package?

• What are the compatibility fallbacks? E.g. net46 → net45 → net40.

• Why do we need platform/host TFMs (e.g. dnxcore50 ) when we can specify dependencies?

dnxcore50

net46 net45 net40

Page 32: .Net Core Blimey! (16/07/2015)

What does this mean for Mono?

Lots. Or not much.

Mono == .NET FrameworkMono already cross platform

Mono’s focus is non-Windows

mobile (Xamarin)

.NET Core’s focus is server and

Windows UWP

Mono can include CoreCLR + CoreFX

code

Page 33: .Net Core Blimey! (16/07/2015)

Where does Roslyn fit in?

Orthogonal.

Runs on .NET Framework + Mono

Planned for.NET Core

CompilingCoreCLR + CoreFX

currently requires Windows

C# compilerwritten in C#

Page 34: .Net Core Blimey! (16/07/2015)

.NET Core

Cross platform

Open Source

NuGet everywhere

Bleeding edge

Icons: http://icons8.com/

The future of .NET

Page 35: .Net Core Blimey! (16/07/2015)

Links

CoreCLR - https://www.github.com/dotnet/coreclr

CoreFX - https://www.github.com/dotnet/corefx

DNX - https://github.com/aspnet/Home

@citizenmatt