Open shmuelie opened 9 months ago
Please check this sample: https://github.com/CodegenCS/Samples/tree/main/src/SampleSourceGenerator.SimplePocos That's a Source Generator, so it adds code dynamically during compilation. Is that what you wanted?
In theory yes, but to quote you:
This is NOT the recommended way of using CodegenCS - it's here only for reference.
Well. I'm biased here - I believe the major feature of CodegenCS is the very precise indent control, so if you don't need (or don't want) to check in the generated code then you don't need CodegenCS, you could just render everything you need into a single file without worrying about making it beautiful or readable. But if you find CodegenCS helps you with that task, why not? Another reason for checking in all sources is that everyone can rebuild without needing any additional tool.
Maybe from the example above (Source Generator) we could transform that into a Nuget that would dynamically run whatever csx script is there. I guess some decisions like "save to file vs generate on the fly" would have to be described somewhere in the CSX scripts.
I mean: there's no technical limitation or strong reason to not use CodegenCS as a Source Generator. It's just me that never had the time or need to explore that enough
Maybe from the example above (Source Generator) we could transform that into a Nuget that would dynamically run whatever csx script is there. I guess some decisions like "save to file vs generate on the fly" would have to be described somewhere in the CSX scripts.
Really like this idea. As for the configuration, maybe it would make more sense to use MSBuild metadata on the CSX files?
I've just published a nuget package with a source generator. Check latest commit (including the updates to the README doc) and let me know how it goes.
In my experience source generators are very troublesome, so unless you're extending on top of the syntax tree I'd assume that calling dotnet-codegencs
in prebuild is a better solution.
Would having MSBuild support be possible? The VS extension is nice but not having to check in the generated code would be nice