Integrating Code Generation into C# Build Process
Hello,
We are working on a C# project where we need to generate part of the C# codebase from source files written in a graphical language. Essentially, a portion of our application is designed using a graphical interface (similar to BPMN) that generates C# code.
We have developed an external application that reads these graphical language files and generates the corresponding C# code. Once generated, this code is built along with the rest of the project.
However, we have been struggling for a few months with how to efficiently include this code generation step in our build process without unnecessarily slowing it down.
Ideally, we would like to achieve the following:
- Trigger code generation before the C# build only when a graphical source file has changed.
- Avoid triggering code generation before the build if no graphical source file has changed.
- Compile the C# code whenever either the C# code or a graphical source file has changed.
- Avoid compiling the C# code if neither the C# code nor any graphical source file has changed.
- Delete the previously generated code before C# compilation whenever code generation occurs.
Currently, our best solution is to update our .csproj file with a Target that runs before the PrebuildEvent target. This target deletes the generated code and regenerates it. Unfortunately, this approach fails to meet goals 2 and 4.
Is there a way (or at least a pointer in the right direction) to gracefully integrate this process into Rider's build mechanism?
Thank you for your help.
Best regards,
Please sign in to leave a comment.
Hello,
Thanks for contacting Rider support. To better understand your situation, could you please provide more details about how code generation is configured and triggered? Is it based on “C# source generator”, or handled by external tools?
Regards,
Tom