Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Roslyn Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Roslyn Cookbook

Roslyn Cookbook

By : Manish Vasani
close
close
Roslyn Cookbook

Roslyn Cookbook

By: Manish Vasani

Overview of this book

Open-sourcing the C# and Visual Basic compilers is one of the most appreciated things by the .NET community, especially as it exposes rich code analysis APIs to analyze and edit code. If you want to use Roslyn API to write powerful extensions and contribute to the C# developer tool chain, then this book is for you. Additionally, if you are just a .NET developer and want to use this rich Roslyn-based functionality in Visual Studio to improve the code quality and maintenance of your code base, then this book is also for you. This book is divided into the following broad modules: 1. Writing and consuming analyzers/fixers (Chapters 1 - 5): You will learn to write different categories of Roslyn analyzers and harness and configure analyzers in your C# projects to catch quality, security and performance issues. Moving ahead, you will learn how to improve code maintenance and readability by using code fixes and refactorings and also learn how to write them. 2. Using Roslyn-based agile development features (Chapters 6 and 7): You will learn how to improve developer productivity in Visual Studio by using features such as live unit testing, C# interactive and scripting. 3. Contributing to the C# language and compiler tool chain (Chapters 8 - 10): You will see the power of open-sourcing the Roslyn compiler via the simple steps this book provides; thus, you will contribute a completely new C# language feature and implement it in the Roslyn compiler codebase. Finally, you will write simple command line tools based on the Roslyn service API to analyze and edit C# code.
Table of Contents (11 chapters)
close
close

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.

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY