Overview of .NET Compiler Platform(Roslyn) and ASP.NET vNEXT
←
→
Page content transcription
If your browser does not render page correctly, please read the page content below
Ovais Mehboob Ahmed Khan Group Leader/Speaker – Microsoft Technology Practices User Group (Meetup.com/MSTPUG) Technical Architect – MS Gold Partner firm Co Founder/Solution Architect - techframeworx Microsoft MVP – ASP.NET/IIS DZone MVB Blog: ovaismehboob.wordpress.com @ovaismehboob
Agenda • Innovations in .NET ecosystem • Overview of .NET Compiler Platform (Roslyn) • Overview of ASP .NET vNext • Demos
Innovation in .NET ecosystem
The .Net Foundation .NET API for Hadoop WebClient Composition (MEF2) MEF (Managed Extensibility Framework) .NET Compiler Platform ("Roslyn") Windows Phone Toolkit .NET Map Reduce API for Hadoop Entity Framework WnsRecipe .NET Micro Framework Rx (Reactive Extensions) Couchbase for .NET ASP.NET Web Pages ASP.NET MVC Xamarin.Mobile System.Drawing ASP.NET Web API Mimekit Mailkit Xamarin.Auth ASP.NET SignalR Web Protection Library OWIN Authentication Middleware Linq to Hive Windows Azure .NET SDK http://www.dotnetfoundation.org @dotnetfdn // #dotnetfdn
Goals of .NET foundation • Open the development process for .NET • Encourage customers, partners and the broader community to participate • Promote innovation by a vibrant partner ecosystem and open source community
.NET Compiler Platform (ROSLYN)
Compiler BLACK Generates Executable BOX
.NET Compiler platform - Roslyn • Compilers become Platform – APIs • C# and VB Compilers written in their own languages • Provides Language Services and APIs on top of .NET Compiler’s Services • Available as CTP (Community Technology preview) • Developers can contribute on codeplex http://roslyn.codeplex.com/
What we can achieve • Use C# and VB as scripting language • Use Compiler as a Service in our applications for code related tasks • Develop IDE extensions • Develop Code Analysis and Diagnostics, etc.
Why rewriting • Complicated design, not easy to change or introduce new language features • Both C# and VB.Net native compilers and IDE services were completely different • Developing Refactoring tools is not an easy job. Required lot of work to reproduce the semantic meaning of the code being refactored.
Roslyn APIs • Scripting API (Not provided with current version of Roslyn) • Provides a runtime execution context for C# and VB.NET. Now you can use C#/VB.NET in your own applications as a scripting language • Compiler API • For accessing the syntax and semantic model of your code. • Workspace API • Provides an object model to aggregate the code model across projects in a solution. Mainly for code analysis and refactoring around IDEs like Visual Studio, though the APIs are not dependent on Visual Studio.
Compiler Pipeline • Exposes Code Analysis by providing an API that mirrors a traditional compiler pipeline
Compiler Pipeline – 4 phases • Parse Phase • Source code tokenized into Syntax tree • Declaration Phase • Declarations from Source Code and Imported Meta data analyzed to form Symbols • Binding Phase • where identifiers in the code are matched to symbols. • Emit Phase • where all the information built up by the compiler is emitted as an assembly.
Compiler Pipeline – Parse Phase • Parse Phase • Source code tokenized into Syntax tree
Syntax Tree • Each element in the Syntax tree is either Syntax Node, Syntax Token or Syntax Trivia • Syntax Node: Combination of other nodes, tokens and trivia • E.g. public String Name{set;get;} • Syntax Token: Individual keywords, symbols and identifiers
Compiler Pipeline – Declaration Phase • Declaration Phase • Represented as a Symbol table
Compiler Pipeline – Binding Phase • Binding Phase • Exposes result of Semantic Analysis • Matched identifiers in the code to symbols • What are identifiers? • Is a name given to namespace, class, method, variable • Starts with alphabet or _ • Cannot start with a digit or any symbol • Cannot contain any symbol except _
Compiler Pipeline – Emit Phase • Binding Phase • Generate Assembly or IL byte codes
Compiler APIs • Syntax API – exposes Syntax Tree • Symbols API – exposes Symbol Table • Binding And Flow Analysis API – exposes the result of Semantic Analysis • Emit API – produces IL byte code
Compiler pipeline functional areas • Visual Studio vNext (CTP 14) uses these APIs, previewed on VS 2013 using Roslyn CTP
How to use • Setup Visual Studio CTP 14 • Install the Visual Studio 14 SDK • Install the SDK Templates VSIX package to get the Visual Studio project templates. • Diagnostic with Code Fix • Code refactoring template • Console Application that uses .Net Compiler Platform assemblies • Install the Syntax Visualizer VSIX package to get a Syntax Visualizer tool window to help explore the syntax trees you'll be analyzing. • Or, Grab the latest NuGet Roslyn compiler package. • Install-Package Microsoft.CodeAnalysis -Pre
Demo 1 Exploring Syntax Tree Visualizer
Syntax • Syntax is about the grammar of the language • Use Parenthesis after Class declaration • Use Braces on Method declaration • Use Parenthesis on Property declaration
Semantics • Semantics is about the meaning of the statement Valid statements i++ For(int i=0;i
Demo 2 Syntax & Semantic Analysis using .NET Compiler Platform
Workspace API • Workspace is a collection of solutions, projects and documents • Starting point for doing code analysis and refactoring over entire solution • Provides Workspace API which helps to access information about all the projects in the solution in a single object model • Offers direct access to source text, syntax trees, semantic models, compilation, manage inter-project dependencies etc. • Tied to the host environment e.g. Visual Studio and fire events when user write code etc.
Demo 3 Diagnostic with Code Fix
ASP.NET VNEXT
ASP .NET History Version Released On Features/Changes ASP.Net 1.0 2002 Web Forms and SOAP based services ASP.Net 2.0 2005 Added features ObjectDataSource and SQLDataSource ASP.NET 3.5 2008 Dynamic Data Support ASP.NET MVC 2009 MVC ASP.NET 4 2012 Added Web API Support ASP.NET 4.5 2013 OWIN and SignalR ASP.Net vNext 2015 (Expected) New Compiler, C# 6.0, MVC, Web API and Web Pages merged into one framework called MVC 6
New approach in .NET
What is ASP .NET VNext • Next generation of .NET on Server • Single programming model for website and services • Low-latency developer experience – refresh on browser recompiles • Delivered via NuGet • No backward compatibility • Release as Open Source via the .NET Foundation • Can run on Mono, Linux and Mac
ASP.Net vNext composed of • Web Pages • MVC • Web API • Signal R
Why Web Forms are not part of ASP.Net vNext • Dropping the dependency on System.Web • Compared to OWIN its slow and monolithic • However, with Visual Studio 2013 Update 2 • Roslyn Support • EF 6 Integration • ASP.Net Identity 2.0 Support • Web Forms Scaffolding support
ASP .NET VNext Totally Modular Much Faster Seamless transition Deploy framework from on-premises to cloud app-by-app basis Open Source with Contributions Cross-Platform
ASP .NET VNext Unified Controller, Routing, Action Low Latency Dev Experience and Filtering for both Web API and MVC NO System.Web Dependency Configuration Host Agnostic
Two Runtimes • Full .NET (200 MB) • .NET Core (~11 MB) • Contains RyuJIT, 64 bit JIT compiler
What is RyuJIT • New next generation x64 bit JIT compiler • 30% faster than standard x64 JIT compiler • Right now available as a CTP
OWIN Compatible • OWIN – Open Web Interface for .Net • Provides abstraction and decouples the interaction between Web Server and Web Applications • Uses Helios to self host Asp.Net vNext application and overlook System.Web
New Files in ASP .NET vNext • Startup.cs • Project.json • Config.json
Comparison b/w .Net vNext and .Net vNext (Cloud Optimized)
Demo 4 Creating and exploring asp.net vNext project in Visual studio 2014
Command Line Tools • KRE (K Runtime) • KVM (K Version Manager) • KPM (K Package Manager) • K (To run commands)
KRE (K Runtime Environment) • K Runtime contains the SDK tools, compilation system and CLR hosts
K Runtime Structure
KVM (K Version Manager) • Allows managing the default version on app to app basis • KVM is essential when you want to self-host ASP.Net vNext application
KVM (K Version Manager) • Allows managing the default version on app to app basis • KVM is essential when you want to self-host ASP.Net vNext application • To Install K Version Manager @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))" • To Install ASP.Net vNext Runtime KVM install 1.0.0-alpha4 • On installing KVM, all the kvm files are copied into the current users directory i.e. %windir%:\Users\%username%\.kre folder KVM upgrade
KVM (K Version Manager) • KVM upgrade Checks the latest KRE version if available and install it on the machine • By default, we are running full .Net Framework but you can switch to the cloud optimized one using kvm upgrade –runtime CoreCLR
KVM (K Version Manager) KVM list • To list the installed version of KRE the * denotes the active version and you can choose another version on app to app basis using kvm use version command
KPM (K Package Manager) KPM restore To restore the packages defined in the project.json file of your ASP.Net vNext application.
K K web K is the command line tool to run ASP.Net vNext application. You can use K run to run the HTTP listener to listen for the incoming request specified in the project.json file
Demo 5 Getting started with ASP.Net vNext project without Visual Studio
Thank you!
You can also read