SkillAgentSearch skills...

Conan

Lightweight fork of the .NET Compiler Platform ("Roslyn") by adding a compiler plugin infrastructure

Install / Use

/learn @conan-roslyn/Conan
About this skill

Quality Score

0/100

Category

Operations

Supported Platforms

Universal

README

Conan Build status

<img align="right" width="256px" height="256px" src="img/conan.png">

Conan is a lightweight fork of the .NET Compiler Platform ("Roslyn") by adding a compiler plugin infrastructure. These plugins can be deployed and installed as regular Diagnostic Analyzers.

Notice

This repository is under construction, a documentation will follow in the coming weeks

Usage

How to develop a Conan compiler plugin?

  1. Create a netstandard1.3 library
  2. Add the latest Conan.CodeAnalysis package (alpha5+)
  3. Create a new class an inherit from CompilationRewriter. See HelloWorld plugin example
        [DiagnosticAnalyzer(LanguageNames.CSharp)]
        public class MyCompilationRewriter : CompilationRewriter
        {
            public override Compilation Rewrite(CompilationRewriterContext context)
            {
                var compilation = context.Compilation;
    
                // Transform compilation
                ...
    
                return compilation;
            }
        }
    
  4. If you want to create a NuGet package for this plugin, you can add a reference to the NuGet package AnalyzerPack and it will transform automatically your package into a Diagnostic Analyzer NuGet package (when doing a dotnet/msbuild Pack)

How to use this plugin in your project?

  1. Add the package Conan.Net.Compilers to your project: This will make the Conan compiler as the default CSharp/VB compiler and replace the default Roslyn compiler (This package works for both Full framework and Core framework unlike the Roslyn packages)
  2. Add your plugin you developed either by:
    • Adding directly a reference to it into your csproj. This is what is used by the HelloWorld package:
        <ItemGroup>
            <Analyzer Include="..\Conan.Plugin.HelloWorld\bin\$(Configuration)\netstandard1.3\Conan.Plugin.HelloWorld.dll" />
        </ItemGroup>
      
    • Adding a reference to the NuGet package of your plugin (that has been through AnalyzerPack)
  3. If you compile your project, the plugin will be automatically loaded and executed, check the logs!

NuGet Packages

Their are 2 fundamental root packages in Conan:

  • Conan.Net.Compilers: This is the Conan compiler that is replacing the default Roslyn compiler, working with both .NET full framework and .NET Core projects. This compiler will be responsible to load your Conan plugins (as Diagnostic Analyzers)
  • Conan.CodeAnalysis: This is the root package for developing a Conan compiler plugin that you should reference from your plugin compiler library

| Roslyn | Conan | NuGet | ------- | -------- | -------- | Microsoft.Net.Compilers<br>Microsoft.NETCore.Compilers | Conan.Net.Compilers | NuGet | Microsoft.CodeAnalysis | Conan.CodeAnalysis | NuGet | • Microsoft.CodeAnalysis.Common | • Conan.CodeAnalysis.Common | NuGet | • Microsoft.CodeAnalysis.CSharp | • Conan.CodeAnalysis.CSharp | NuGet | • Microsoft.CodeAnalysis.CSharp.Workspaces | • Conan.CodeAnalysis.CSharp.Workspaces | NuGet | • Microsoft.CodeAnalysis.VisualBasic | • Conan.CodeAnalysis.VisualBasic | NuGet | • Microsoft.CodeAnalysis.VisualBasic.Workspaces | • Conan.CodeAnalysis.VisualBasic.Workspaces | NuGet | • Microsoft.CodeAnalysis.Workspaces.Common | • Conan.CodeAnalysis.Workspaces.Common | NuGet

Credits

All the people involved behind the .NET Compiler Platform ("Roslyn"). Conan is a very little addition to the huge work already done there.

The logo is called Lion created by Jennifer Keana from the Noun Project

Licensing

Same license than Roslyn: Apache-2.0

Author

Alexandre MUTEL aka xoofx

View on GitHub
GitHub Stars97
CategoryOperations
Updated2y ago
Forks3

Languages

C#

Security Score

70/100

Audited on Jan 27, 2024

No findings