328 lines
17 KiB
HTML
328 lines
17 KiB
HTML
<p align="center">
|
||
<a href="https://github.com/dotnet/roslyn">
|
||
<img src="https://raw.githubusercontent.com/ironcev/awesome-roslyn/master/images/awesome-roslyn-logo.png" alt="Awesome Roslyn" width="500">
|
||
</a>
|
||
</p>
|
||
<p align="center">
|
||
<a href="https://github.com/sindresorhus/awesome">
|
||
<img src="https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg" alt="Awesome">
|
||
</a>
|
||
</p>
|
||
<blockquote>
|
||
<p>Curated list of Roslyn books, tutorials, open source projects,
|
||
analyzers, code fixes, refactorings, and source generators.</p>
|
||
</blockquote>
|
||
<p>Roslyn, officially named <a
|
||
href="https://en.wikipedia.org/wiki/.NET_Compiler_Platform">.NET
|
||
Compiler Platform</a>, is a set of open-source compilers and code
|
||
analysis APIs for C# and Visual Basic .NET languages.</p>
|
||
<h2 id="contents">Contents</h2>
|
||
<ul>
|
||
<li><a href="#books">Books</a></li>
|
||
<li><a href="#tutorials">Tutorials</a></li>
|
||
<li><a href="#open-source-projects">Open Source Projects</a></li>
|
||
<li><a href="#open-source-analyzers-code-fixes-and-refactorings">Open
|
||
Source Analyzers, Code Fixes, and Refactorings</a></li>
|
||
<li><a
|
||
href="#libraries-and-frameworks-for-testing-analyzers-code-fixes-and-refactorings">Libraries
|
||
and Frameworks for Testing Analyzers, Code Fixes, and
|
||
Refactorings</a></li>
|
||
<li><a href="#source-generators">Source Generators</a></li>
|
||
<li><a href="#blog-posts-and-articles">Blog Posts and Articles</a></li>
|
||
<li><a href="#talks">Talks</a></li>
|
||
</ul>
|
||
<h2 id="books">Books</h2>
|
||
<p>Awesome books to give you a good start with Roslyn.</p>
|
||
<ul>
|
||
<li><a href="https://www.syncfusion.com/ebooks/roslyn">Roslyn
|
||
Succinctly</a> - <em>Free e-book</em> by Alessandro Del Sole and the
|
||
perfect book to start with. Explains Roslyn APIs and afterward focuses
|
||
on writing analyzers and refactorings.</li>
|
||
<li><a href="https://www.apress.com/la/book/9781484221105">.NET
|
||
Development Using the Compiler API</a> - Book by Jason Bock. Besides
|
||
analyzers and refactorings, it also explains the scripting API and
|
||
provides an interesting reflection on the future of the Compiler
|
||
API.</li>
|
||
<li><a
|
||
href="https://www.packtpub.com/application-development/roslyn-cookbook">Roslyn
|
||
Cookbook</a> - Book by Manish Vasani, a member of the Roslyn analyzers
|
||
team. After covering analyzers, refactorings, and scripting in detail,
|
||
the book goes in-depth explaining how to develop new C# language
|
||
features and contribute to the Roslyn source code.</li>
|
||
</ul>
|
||
<h2 id="tutorials">Tutorials</h2>
|
||
<p>Awesome online tutorials to help you write your first analyzers, code
|
||
fixes, and source generators.</p>
|
||
<ul>
|
||
<li><a href="https://joshvarty.com/learn-roslyn-now/">Learn Roslyn
|
||
Now</a> - Series of blog posts that explore the Roslyn compiler API. It
|
||
introduces the power of Roslyn through small self-contained examples. A
|
||
perfect tutorial to start with :-)</li>
|
||
<li><a
|
||
href="https://github.com/dotnet/roslyn/blob/master/docs/wiki/How-To-Write-a-C%23-Analyzer-and-Code-Fix.md">How
|
||
To Write a C# Analyzer and Code Fix</a> - The mother of all Roslyn
|
||
tutorials :-) A realistic step-by-step introduction to syntax and
|
||
semantic analysis as well as the syntax transformation.</li>
|
||
<li><a href="https://msdn.microsoft.com/en-us/magazine/dn879356.aspx">C#
|
||
and Visual Basic - Use Roslyn to Write a Live Code Analyzer for Your
|
||
API</a> - Older but still not outdated, very detailed MSDN article on
|
||
writing code analyzers.</li>
|
||
<li><a href="https://msdn.microsoft.com/en-us/magazine/dn904670.aspx">C#
|
||
- Adding a Code Fix to Your Roslyn Analyzer</a> - The sequel to the
|
||
previous MSDN article. A detailed introduction into code fixes.</li>
|
||
<li><a
|
||
href="https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/">Introducing
|
||
C# Source Generators</a> - Original announcement of the C# 9.0 Source
|
||
Generators feature. Explains what source generators are, in which
|
||
scenarios they are useful, and shows how to write a simple source
|
||
generator.</li>
|
||
<li><a
|
||
href="https://devblogs.microsoft.com/dotnet/new-c-source-generator-samples/">New
|
||
C# Source Generator Samples</a> - Samples on how to write a non-trivial
|
||
code generator driven by additional, non-code files like CSV files or <a
|
||
href="https://mustache.github.io/">Mustache</a> templates.</li>
|
||
<li><a href="https://github.com/amis92/csharp-source-generators">C#
|
||
Source Generators</a> - Comprehensive list of additional learning
|
||
sources, samples, and experimental and productive source generators. A
|
||
perfect reference once you grasp the basics.</li>
|
||
</ul>
|
||
<h2 id="open-source-projects">Open Source Projects</h2>
|
||
<p>Awesome open source projects built on top of Roslyn.</p>
|
||
<ul>
|
||
<li><a href="https://github.com/bridgedotnet/Bridge">Bridge</a> - C# to
|
||
JavaScript transpiler. Write modern mobile and web apps in C# and run
|
||
them anywhere in JavaScript.</li>
|
||
<li><a href="https://github.com/icsharpcode/CodeConverter/">Code
|
||
Converter</a> - C# to VB.NET and VB.NET to C# transpiler.</li>
|
||
<li><a
|
||
href="https://github.com/pvginkel/Microsoft.CodeAnalysis.CSharp.PatternMatching">CodeAnalysis.CSharp.PatternMatching</a>
|
||
- Intuitive pattern matching for Roslyn syntax trees. Simplifies C#
|
||
syntax and semantic analysis.</li>
|
||
<li><a
|
||
href="https://github.com/AArnott/CodeGeneration.Roslyn">CodeGeneration.Roslyn</a>
|
||
- Roslyn-based Code Generation during a build with design-time
|
||
support.</li>
|
||
<li><a href="https://github.com/filipw/dotnet-script">dotnet-script</a>
|
||
- Runs C# scripts from the .NET CLI, defines NuGet packages inline and
|
||
edit/debugs them in VS Code.</li>
|
||
<li><a href="https://github.com/dotnetcore/FlubuCore">FlubuCore</a> -
|
||
Cross platform build automation tool for building projects and executing
|
||
deployment scripts using C# code.</li>
|
||
<li><a href="https://github.com/ashmind/mirrorsharp">MirrorSharp</a> -
|
||
Online C#, VB.NET, and F# code editor. Features code completion, method
|
||
signature help, quick fixes, and diagnostics.</li>
|
||
<li><a href="http://www.omnisharp.net/">OmniSharp</a> - Enables a cross
|
||
platform .NET development in the editor of your choice. A family of open
|
||
source projects, each with one goal: To enable a great .NET experience
|
||
in your editor of choice.</li>
|
||
<li><a
|
||
href="https://github.com/antiufo/roslyn-linq-rewrite">roslyn-linq-rewrite</a>
|
||
- Compiles C# code by first rewriting the syntax trees of LINQ
|
||
expressions using plain procedural code. This increases performance by
|
||
minimizes heap allocations and dynamic dispatch.</li>
|
||
<li><a href="https://roslynpad.net/">RoslynPad</a> - Cross-platform C#
|
||
editor. Features code completion, method signature help, quick fixes,
|
||
and diagnostics.</li>
|
||
<li><a
|
||
href="https://github.com/KirillOsenkov/RoslynQuoter">RoslynQuoter</a> -
|
||
Online tool that for a given C# program generates syntax tree API calls
|
||
that construct syntax tree of that program.</li>
|
||
<li><a href="http://scriptcs.net/">scriptcs</a> - Turns C# into a
|
||
powerful scripting tool. Features C# REPL, installation of NuGet
|
||
packages, and execution of scripts with a single line of code.</li>
|
||
<li><a href="https://github.com/daveaglick/Scripty">Scripty</a> - Tool
|
||
to use Roslyn-powered C# scripts for code generation. You can think of
|
||
it as a scripted alternative to T4 templates.</li>
|
||
<li><a href="http://sharpen.rocks">Sharpen</a> - Visual Studio extension
|
||
that intelligently introduces new C# language features into your
|
||
existing code base.</li>
|
||
<li><a href="https://sharplab.io/">SharpLab</a> - .NET code playground.
|
||
Displays intermediate steps and results of code compilation. Shows the
|
||
code as compiler sees it. Allows selecting different branches and
|
||
versions of Roslyn. Runs C#, VB.NET, and F# code in the browser.</li>
|
||
<li><a href="https://github.com/Testura/Testura.Code">Testura.Code</a> -
|
||
Wrapper around the Roslyn API used for generation, saving, and compiling
|
||
C# code. Provides methods and helpers to generate classes, methods,
|
||
statements, and expressions.</li>
|
||
<li><a href="https://github.com/nventive/Uno.SourceGeneration">Uno
|
||
SourceGenerator</a> - C# source code generator based on a project being
|
||
built, using all of its syntactic and semantic model information.</li>
|
||
</ul>
|
||
<h2 id="open-source-analyzers-code-fixes-and-refactorings">Open Source
|
||
Analyzers, Code Fixes, and Refactorings</h2>
|
||
<p>Awesome open source analyzers, code fixes, and refactorings.</p>
|
||
<ul>
|
||
<li><a href="https://github.com/DotNetAnalyzers">.NET Analyzers</a> -
|
||
GitHub organization for the development of Roslyn analyzers. Various
|
||
repositories within the organization cover analyzers for ASP.NET Core,
|
||
WPF, IDisposable, usages of System.Reflection, etc.</li>
|
||
<li><a href="https://github.com/dotnet/roslyn-analyzers">.NET Compiler
|
||
Platform (“Roslyn”) Analyzers</a> - Diagnostic analyzers developed by
|
||
the Roslyn team. Initially developed to help flesh out the design and
|
||
implementation of the static analysis APIs. The analyzers cover code
|
||
quality, .NET Core, desktop .NET Framework, comments in code, and
|
||
more.</li>
|
||
<li><a href="https://github.com/code-cracker/code-cracker">Code
|
||
Cracker</a> - Analyzer library for C# and VB.NET. Offers diagnostics in
|
||
many categories like performance, coding styles, as well as some basic
|
||
refactorings.</li>
|
||
<li><a
|
||
href="https://github.com/bkoelman/CSharpGuidelinesAnalyzer">CSharpGuidelinesAnalyzer</a>
|
||
- Reports diagnostics for C# coding guidelines
|
||
(https://csharpcodingguidelines.com/).</li>
|
||
<li><a
|
||
href="https://github.com/SergeyTeplyakov/ErrorProne.NET">ErrorProne.NET</a>
|
||
- Set of analyzers and code fixes focusing on the correctness and
|
||
performance of C# programs. Inspired with Google’s <a
|
||
href="https://github.com/google/error-prone">Error Prone</a>.</li>
|
||
<li><a href="https://github.com/cezarypiatek/MappingGenerator">Mapping
|
||
Generator</a> - Code fix that generates arbitrary complex object-object
|
||
mappings. It recognizes out of the box a large number of scenarios where
|
||
mappings are used. A design-time alternative to <a
|
||
href="https://automapper.org/">AutoMapper</a>.</li>
|
||
<li><a
|
||
href="https://github.com/tom-englert/Nullable.Extended">Nullable.Extended</a>
|
||
- Roslyn tools and analyzers to improve the experience when coding with
|
||
nullable reference types.</li>
|
||
<li><a
|
||
href="https://github.com/icsharpcode/RefactoringEssentials/">Refactoring
|
||
Essentials for Visual Studio</a> - Refactorings, analyzers and code
|
||
fixes for C# and VB.NET.</li>
|
||
<li><a
|
||
href="https://github.com/Microsoft/RoslynClrHeapAllocationAnalyzer">Roslyn
|
||
Clr Heap Allocation Analyzer</a> - C# heap allocation analyzer that can
|
||
detect explicit and many implicit allocations like boxing, closures,
|
||
implicit delegate creations, etc.</li>
|
||
<li><a href="https://github.com/JosefPihrt/Roslynator">Roslynator</a> -
|
||
Collection of 190+ analyzers and 190+ refactorings for C#. Covers coding
|
||
style, code readability and simplification, removing redundancies,
|
||
fixing compiler errors, and many more.</li>
|
||
<li><a href="https://github.com/SonarSource/sonar-csharp">SonarC#</a> -
|
||
Static code analyzer for C# language used as an extension for the
|
||
SonarQube platform.</li>
|
||
<li><a
|
||
href="https://github.com/DotNetAnalyzers/StyleCopAnalyzers">StyleCop
|
||
Analyzers for the .NET Compiler Platform</a> - Port of StyleCop rules to
|
||
Roslyn.</li>
|
||
<li><a
|
||
href="https://github.com/Vannevelj/VSDiagnostics">VSDiagnostics</a> -
|
||
Collection of code-quality analyzers. Covers usages of async methods,
|
||
flags enums, best practices in exception handling as well as many other
|
||
code-quality checks.</li>
|
||
</ul>
|
||
<h2
|
||
id="libraries-and-frameworks-for-testing-analyzers-code-fixes-and-refactorings">Libraries
|
||
and Frameworks for Testing Analyzers, Code Fixes, and Refactorings</h2>
|
||
<p>Awesome libraries and frameworks for testing analyzers, code fixes,
|
||
and refactorings.</p>
|
||
<ul>
|
||
<li><a
|
||
href="https://github.com/dotnet/roslyn-sdk/tree/master/src/Microsoft.CodeAnalysis.Testing">Microsoft.CodeAnalysis.Testing</a>
|
||
- Library for testing analyzers and code fixes with NUnit, xUnit and
|
||
MSTest frameworks. A part of <a
|
||
href="https://github.com/dotnet/roslyn-sdk">Roslyn SDK</a>.</li>
|
||
<li><a
|
||
href="https://github.com/cezarypiatek/RoslynTestKit">RoslynTestKit</a> -
|
||
Lightweight framework for writing unit tests for analyzers, code fixes,
|
||
refactorings, and completion providers. It’s unit testing framework
|
||
agnostic.</li>
|
||
</ul>
|
||
<h2 id="source-generators">Source Generators</h2>
|
||
<p>Awesome (but mostly experimental at the moment, because .NET 5.0 and
|
||
C# 9.0 are still in preview) source generators and open source projects
|
||
that internally use source generators.</p>
|
||
<ul>
|
||
<li><a href="https://github.com/lsoft/DpdtInject">DpDtInject</a> -
|
||
Proof-of-concept of a dependency injection container that transfers huge
|
||
piece of resolving logic to the compilation stage. Offers additional
|
||
compile-time safety and fast runtime resolution.</li>
|
||
<li><a
|
||
href="https://github.com/diegofrata/Generator.Equals">Generator.Equals</a>
|
||
- Automatically implements equality and hashing for classes and records.
|
||
Supports different comparison strategies. Offers similar functionality
|
||
like IL weaving-based <a
|
||
href="https://github.com/Fody/Equals">Equals.Fody</a>.</li>
|
||
<li><a href="https://github.com/trampster/JsonSrcGen">JsonSrcGen</a> -
|
||
Reflection-free JSON serializer. Allows extremely fast JSON processing
|
||
by generating reflection-free serializers at the compile time.</li>
|
||
<li><a href="https://sourcegen.dev/">Source Generator Playground</a> -
|
||
Online application that lets you experiment with source generators.
|
||
Perfect for learning and testing your ideas. Write your own source
|
||
generator or learn from built-in examples and see the generated
|
||
output.<br />
|
||
</li>
|
||
<li><a
|
||
href="https://github.com/YairHalberstadt/stronginject">StrongInject</a>
|
||
- Compile-time dependency injection container. Compile-time checked,
|
||
reflection-free and runtime code generation free, thus fast and <a
|
||
href="https://devblogs.microsoft.com/dotnet/app-trimming-in-net-5/">app-trimming</a>-friendly.</li>
|
||
<li><a
|
||
href="https://github.com/RudolfKurka/StructPacker">StructPacker</a> -
|
||
Low-level, lightweight and performance-focused serializer for C# struct
|
||
types. Auto-generates C# serialization code to achieve peak runtime
|
||
performance and efficiency.</li>
|
||
<li><a href="https://github.com/wieslawsoltes/SourceGenerators">Svg to
|
||
C# Source Generators</a> - SVG to C# compiler. Compiles SVG drawing
|
||
markup to C# using <a
|
||
href="https://github.com/mono/SkiaSharp">SkiaSharp</a> as rendering
|
||
engine.</li>
|
||
<li><a
|
||
href="https://github.com/martinothamar/WrapperValueObject">WrapperValueObject</a>
|
||
- Creates boilerplate free wrappers around types. Especially useful for
|
||
creating <a
|
||
href="https://andrewlock.net/series/using-strongly-typed-entity-ids-to-avoid-primitive-obsession/">strongly
|
||
typed wrappers around primitive types</a>.</li>
|
||
</ul>
|
||
<h2 id="blog-posts-and-articles">Blog Posts and Articles</h2>
|
||
<p>Awesome blog posts and online articles covering various topics like
|
||
performance, Roslyn history, internals and similar.</p>
|
||
<ul>
|
||
<li><a
|
||
href="https://medium.com/microsoft-open-source-stories/how-microsoft-rewrote-its-c-compiler-in-c-and-made-it-open-source-4ebed5646f98">How
|
||
Microsoft rewrote its C# compiler in C# and made it open source</a> -
|
||
Roslyn’s journey, presented by Mads Torgersen, the lead designer of C#.
|
||
Inspiring story on how Roslyn project started and why, and what it took
|
||
to make it open source.</li>
|
||
<li><a
|
||
href="https://robinsedlaczek.com/2015/04/29/inside-the-net-compiler-platform-performance-considerations-during-syntax-analysis-speakroslyn/">Inside
|
||
the .NET Compiler Platform – Performance Considerations during Syntax
|
||
Analysis (#SpeakRoslyn)</a> - In-depth look at Roslyn’s performance with
|
||
the focus on memory consumption.</li>
|
||
<li><a
|
||
href="https://blogs.msdn.microsoft.com/ericlippert/2012/06/08/persistence-facades-and-roslyns-red-green-trees/">Persistence,
|
||
Facades and Roslyn’s Red-Green Trees</a> - Inspiring introduction on how
|
||
Roslyn team implemented immutable, reusable trees with cheap parent
|
||
references and many other goodies. Quote: “But on the Roslyn team we
|
||
routinely do impossible things” :-)</li>
|
||
<li><a
|
||
href="https://blog.jetbrains.com/dotnet/2014/04/10/resharper-and-roslyn-qa/">ReSharper
|
||
and Roslyn: Q&A</a> - Excellent explanation why ReSharper will not
|
||
use Roslyn. Includes good discussion on static code analysis and some
|
||
limits of Roslyn.</li>
|
||
<li><a
|
||
href="https://blogs.msdn.microsoft.com/csharpfaq/2014/01/15/roslyn-performance-matt-gertz/">Roslyn
|
||
performance (Matt Gertz)</a> - Insight on how Roslyn team approaches the
|
||
topic of evaluating and achieving performance.</li>
|
||
</ul>
|
||
<h2 id="talks">Talks</h2>
|
||
<p>Awesome public talks about Roslyn.</p>
|
||
<ul>
|
||
<li><a href="https://www.youtube.com/watch?v=nXljhGDokqA">The Power of
|
||
Roslyn</a> - Great talk by Kasey Uhlenhuth at NDC Oslo 2018 covering
|
||
Roslyn essentials and APIs and tools for building code analyzers and
|
||
fixes.</li>
|
||
</ul>
|
||
<h2 id="contribute">Contribute</h2>
|
||
<p>Contributions are welcome :-) The goal is to build a categorized
|
||
community-driven collection of awesome Roslyn resources. Before
|
||
contributing, please make sure to read the <a
|
||
href="contributing.md">contribution guidelines</a>.</p>
|
||
<h2 id="license">License</h2>
|
||
<p><a href="http://creativecommons.org/publicdomain/zero/1.0"><img
|
||
src="http://mirrors.creativecommons.org/presskit/buttons/88x31/svg/cc-zero.svg"
|
||
alt="CC0" /></a></p>
|
||
<p>To the extent possible under law, Igor Rončević has waived all
|
||
copyright and related or neighboring rights to this work.</p>
|
||
<p><a href="https://github.com/ironcev/awesome-roslyn">roslyn.md
|
||
Github</a></p>
|