CodegenCS icon indicating copy to clipboard operation
CodegenCS copied to clipboard

MSBuild Tooling

Open shmuelie opened this issue 2 years ago • 6 comments

Would having MSBuild support be possible? The VS extension is nice but not having to check in the generated code would be nice

shmuelie avatar Oct 02 '23 15:10 shmuelie

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?

Drizin avatar Oct 03 '23 02:10 Drizin

In theory yes, but to quote you:

This is NOT the recommended way of using CodegenCS - it's here only for reference.

shmuelie avatar Oct 03 '23 15:10 shmuelie

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.

Drizin avatar Oct 03 '23 17:10 Drizin

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

Drizin avatar Oct 03 '23 17:10 Drizin

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?

shmuelie avatar Oct 09 '23 15:10 shmuelie

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 (example here)

Drizin avatar Jul 01 '24 04:07 Drizin

@shmuelie I've also published a MSBuild Task. Would you like to test and let me know how it goes? Thanks

Drizin avatar Jul 08 '24 03:07 Drizin

@Drizin, been busy on some other projects. Once I have the time, I'll give this all a try again, thanks!!!

shmuelie avatar Jul 09 '24 15:07 shmuelie