Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Raffaele Rialdi (Vevy Europe), Backend Introduction to .NET Core with VS2017, CodeFest 2017

CodeFest
January 31, 2018

Raffaele Rialdi (Vevy Europe), Backend Introduction to .NET Core with VS2017, CodeFest 2017

https://2017.codefest.ru/lecture/1153

The new .NET Core is a flavor of the .NET Framework that will rapidly spread thanks to a number of important pillars: designed to be cross-platform and cross-device; cutting dependencies to make the deploying story easy and lightweight; defining a new standard library contract to make libraries even more reusable.

What are the effort to bring the current .NET Framework code to NetCore? How can we migrate the code in small steps? How does it work the deploy cross-platform?

During the session we will make a broad overview for people that is already familiar with the current .NET Framework and try to give practical answers for those who want to try embracing the new NetCore on current real projects.

CodeFest

January 31, 2018
Tweet

More Decks by CodeFest

Other Decks in Programming

Transcript

  1. Who am I? • I am Raffaele Rialdi, Senior Software

    Architect in Vevy Europe – Italy • I am also consultant in many industries (manufacturing, racing, healthcare, financial, …) • But also Speaker in italian and international conferences, and Trainer as well • And very proud to have been awarded as a Microsoft MVP since 2003 @raffaeler [email protected] github.com/raffaeler
  2. .NET Framework (version 1.0 - 4.62) • 15 years, 1.8

    billion installations • Multiple codebases • Desktop, Silverlight • x86 - Windows • Compact Framework • ARM – Windows CE • Micro Framework • ARM • Non-Microsoft .NET • Mono / Xamarin • Linux, iOS, MacOS, … • x86 and ARM .NET Framework Common Language Specification VB C++ C# F# … Common Language Runtime (CLR) Base Class Library (BCL) Ado.net Asp.net Winform WPF ... Multiple BCL codebases .NET Mono & Unity Compact Framewor k Micro Framewor k Silverlig ht .. . The number of APIs is not proportional to the bars
  3. What is NET Core? • Technically a «fork» of the

    .NET Framework • New runtime (Common Language Runtime – CLR) • New libraries (Base Class Library – BCL) • Changes to make the Cross Platform story work • Scenarios taking advantage from Net Core (currently) are: • ASP.NET Core: new ASP.NET stack, re-written from scratch • Containerized applications / docker - ready • Cloud Applications: Applications and Microservices running on Azure • Universal Windows Platform: Windows Store Apps (cross-device) • Console Application: the best way to start testing Net Core
  4. Cross-Platform = No first-class Operating System • Official daily compilations

    on GitHub include many OSes • CentOS, Debian, FreeBSD, openSUSE, RedHat, Linux Mint, Ubuntu 14.04 to 16.10, Alpine Linux, … • OSX 10.11 • Windows Occasionally this may happen :)
  5. The Big Picture • Libraries using just CoreFX can be

    shared across all the Application Models • Runtime Adaptation Layers are specific to a given Platform / CPU • x86, x64, ARM, ... (more CPUs are coming in town) • Modular design for future extensions • New Application Models • New Operating Systems / Platforms • New CLR variants Runtime Adaption Level CoreCLR .NET Native … .NET Standard Library Runtime Adaption Level … … ASP.NET WPF Win Forms ASP.NET CORE UWP OS X iOS Android .NET Framework "Classic" .NET CORE Xamarin / Mono CoreFX
  6. The unified Command Line called "dotnet" • The CLI (Command

    Line Interface) is back • In the cross-platform world is the common denominator • Nanoservers, IoT devices, etc. are controlled using the command line • Deploy tasks can be automated • Easy to install on a fresh machine • Visual Studio will provide the UI for all the CLI commands • Support "extensions" to add commands • downloaded via dotnet restore
  7. Hands on the DotNet CLI 1. Install the CLI 2.

    Create an App 3. Write some code 4. Restore packages 5. Run the app mkdir myapp cd myapp dotnet new dotnet restore http://dot.net/ http://dot.net/ Commands: new Initialize .NET projects. restore Restore dependencies specified in the .NET project. build Builds a .NET project. publish Publishes a .NET project for deployment (including the runtime). run Compiles and immediately executes a .NET project. test Runs unit tests using the test runner specified in the project. pack Creates a NuGet package. migrate Migrates a project.json based project to a msbuild based project. clean Clean build output(s). sln Modify solution (SLN) files. Project modification commands: add Add items to the project remove Remove items from the project list List items in the project Advanced Commands: nuget Provides additional NuGet commands. msbuild Runs Microsoft Build Engine (MSBuild). vstest Runs Microsoft Test Execution Command Line Tool. dotnet run ... https://github.com/dotnet/cli
  8. Netstandard • A library specification defining a set of APIs

    with no implementation • Think to netstandard as it was a huge interface • All NET Frameworks must implement all those APIs • CoreFX is a superset of netstandard • https://github.com/dotnet/corefx • The review board defines the number of netstandard APIs • No platform specific APIs but abstractions to access to the OS services • Only APIs that should be always available • Netstandard avoid the confusion of external libraries • NodeJS suffers from this problem https://github.com/dotnet/standard/
  9. NetStandard versions vs Platforms Framework TFM .NET Standard netstandard 1.0

    1.1 1.2 1.3 1.4 1.5 1.6 2.0 .NET Core netcoreapp 1.0 2.0 .NET Framework net 4.5 4.5.1 4.6 4.6.1 4.6.2 vNext 4.6.1 Mono / Xamarin - vNext UWP uap vNext Windows win 8.0 8.1 Windows Phone wpa 8.1 Silverlight wp 8.0 (obsolete frameworks) more APIs more Frameworks Unity Game Framework is going to support netstandard 2.0 Version # of APIs netstandard 1.6 13,501 netstandard 2.0 32,638
  10. API Cross-Reference • A cross-reference with all .NET APIs •

    Availability of every APIs in the .NET Framework, Mono, Net Core, … • Answers to the question: which framework does support this API? http://apisof.net
  11. Packages • Nuget is the package manager in the .net

    environment • There is a 1:1:1 relationship among namespace, dll and package • System.Reflection => System.Reflection.dll => Sytem.Reflection.nupkg • Every package may be released "out of band" • No more waiting for the next «.Net Framework Runtime» • A Metapackage is a 'fake' package redirecting to several real packages • It does not contain dlls but just references to other packages
  12. Metapackages • Metapackages makes developer's life easier • They are

    predefined sets of commonly used packages • The NETStandard.Library Metapackage • It references the libraries that are part of the ".NET Standard Library" • The Microsoft.NETCore.App Metapackage • It references the libraries that are part of the .NET Core distribution • It is a larger set than NETStandard.Library • The Microsoft.NETCore.Portable.Compatibility Metapackage • The compatibility façades enabling PCLs based on mscorlib to run on NetCore
  13. How Projects specify the framework • A NetCore app /

    library • targets • references Microsoft.NETCore.App • A Netstandard library targets • targets • references NETStandard.Library • Future 2.0 netcore apps • targets • To run on a specific framework version (this may change in the future) <TargetFramework>netcoreapp1.1</TargetFramework> <TargetFramework>netstandard1.4</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework> <RuntimeFrameworkVersion>2.0.0-beta-25108-01</RuntimeFrameworkVersion>  Never reference these metapackages in the nuget references
  14. Self-Contained Depolyment (SCD) • Visual Studio 2017 has a "Publish"

    menu in the solution explorer • Using the CLI: • The RIDs (Runtime Identifiers) must be specified in the csproj • The nuget package Microsoft.NETCore.Platforms contains the all the available RIDs <RuntimeIdentifiers>win8-arm;ubuntu.14.04-arm;ubuntu.16.04-arm</RuntimeIdentifiers> dotnet publish –r ubuntu.14.04-arm –o folder –c Release
  15. Reducing the footprint of the SCD • Replace netcoreapp1.1 with

    netstandard1.6 • Explicitly reference these base packages <ItemGroup> <PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR" Version="1.0.2" /> <PackageReference Include="Microsoft.NETCore.DotNetHostPolicy" Version="1.0.1" /> </ItemGroup> <TargetFramework>netstandard1.6</TargetFramework> Standard templates Console WebApp Default win10-x64 45.6 MB 55.5 MB Default ubuntu.16.04-x64 52.6 MB 62.6 MB Reduced win10-x64 28.5 MB 47.4 MB Reduced ubuntu.16.04-x64 36.8 MB 55.9 MB
  16. Why adopting Net Core? • It's fast! • https://github.com/aspnet/benchmarks •

    It small and ready for container and microsevices! • Docker on x86-x64 is already available! • With 2.0 we will have Docker on ARM devices • It's the familiar .NET you already know! • Netstandard libraries can be used across all the frameworks • The upcoming 2.0 version will provide a shim for cross-framework calls
  17. What's next? • ARM support is coming with netcore 2.0

    and netstandard 2.0 • Come to the Exhibition Zone to see a demo with a Raspberry PI! • Interoperability with Node.JS • Come to my session tomorrow, April 2nd, 1.30 - 2.10pm • Use your C# libraries from Node.JS