Skip to content

Latest commit

 

History

History

MSBuild

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

CodegenCS is a Toolkit for doing Code Generation using plain C#.

Before anything else, don't forget to read the Main Project Page to learn the basics (basic idea, basic features, and major components).

This page is only about CodegenCS Source Generator:

CodegenCS MSBuild Task

Our MSBuild Task allows running templates on-the-fly during compilation.

MSBuild Task CodegenBuildTask is automatically invoked during BeforeCompile target, will search for *.csx files in the project folder and will run each one. Files are physically saved to disk and will be automatically added to your compilation.

Quickstart

  1. Install nuget CodegenCS.MSBuild to your project

    <ItemGroup>
      <PackageReference Include="CodegenCS.MSBuild" Version="3.5.2" PrivateAssets="All" />
    </ItemGroup>
  2. Create a CodegenCS template in your project (name it with CSX extension). Example:

     class Template
     {
         void Main(ICodegenContext context)
         {
             context[$"MyClass1.g.cs"].Write($$"""
                 public class MyClas1
                 {
                 }
                 """);
         }
     }

    See full examples: SDK-project and non-SDK-project.