Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Roslyn Cookbook

You're reading from   Roslyn Cookbook Compiler as a Service, Code Analysis, Code Quality and more

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781787286832
Length 350 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Manish Vasani Manish Vasani
Author Profile Icon Manish Vasani
Manish Vasani
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Writing Diagnostic Analyzers FREE CHAPTER 2. Consuming Diagnostic Analyzers in .NET Projects 3. Writing IDE Code Fixes, Refactorings, and Intellisense Completion Providers 4. Improving Code Maintenance of C# Code Base 5. Catch Security Vulnerabilities and Performance Issues in C# Code 6. Live Unit Testing in Visual Studio Enterprise 7. C# Interactive and Scripting 8. Contribute Simple Functionality to Roslyn C# Compiler Open Source Code 9. Design and Implement a New C# Language Feature 10. Command-Line Tools Based on Roslyn API

Preface

Software developers deal with source code on a day-to-day basis. Regardless of the technology or the programming language that they work on, there are a bunch of routine tasks that they must perform on their code:

  • Compile source code into the runtime-specific binary format
  • Analyze source code to identify issues in the source code
  • Edit source code to fix issues or refactor to improve maintenance, understandability, performance, security, and so on
  • Navigate source code to search patterns, references, definitions, and relationships
  • Debug source code to observe and fix runtime behavior for functionality, performances, security, and so on
  • Visualize collections of source components (projects), their properties, configuration, and so on

The .NET Compiler Platform (code named Roslyn) is a platform for .NET programming languages, C# and Visual Basic, to enable building tools and extensions to perform these routine programming tasks. Notably, this platform is shared between Microsoft s .NET compilers and the Visual Studio IDE for .NET development.

Roslyn is divided into multiple programming layers, with each layer exposing public APIs to write customized tools and extensions:

  • CodeAnalysis layer: Core syntax and semantic representation layer of source code. C# and Visual Basic compilers (csc.exe and vbc.exe) are written on top of this layer.
  • Workspaces layer: Project and solution layer that collects a set of logically related source files. These are not coupled to any specific host, such as Visual Studio.
  • Features layer: Set of IDE features built on top of the CodeAnalysis and Workspaces API such as code fixes, refactorings, IntelliSense, completion, finding references, and navigating to definition and so on. These are not coupled to any specific host, such as Visual Studio.
  • Visual Studio layer: Visual Studio workspace and project system that brings together and lights up all the compiler and IDE features.

Roslyn is essentially a stack of services that has been written with two core design principles: Extensibility (for layers above and third-party plugins) and Maintainability (it has well-documented and supported public APIs across these layers). External developers or third parties can do bunch of cool stuff on top of these services:

  • Write their own tools for any specific programming layer to accomplish any of the programming tasks noted previously.
  • Write simple plugins (for example diagnostic analyzers, code fixes and refactorings, completion and IntelliSense providers) for specific layers.
  • Perform advanced scenarios at any specific layer, such as implementing their own compiler, Workspace, IDE, or project system, and all the other functionality across the stack lights up automagically.
lock icon The rest of the chapter is locked
Next Section arrow right
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image