How to generate non-source files (e.g. json) in C#/ .NET 5

Viewed 188

I've started using Source Generator in .NET 5 to generate some custom serialization code. This works beautifully for my use case. However I'd also like to create a custom schema for said serializer in the form of a JSON file. Unfortunately, I haven't been able to find a way to output said generated file using Source Generators. Is this possible at all? Or perhaps I should use some other method of generation?

1 Answers

This is a scenario we're actively looking at, but don't have the current bandwidth to implement. We did some early work to see how it would work for analyzers here: https://github.com/dotnet/roslyn/pull/49046

Logically that work would flow to generators as well, but as noted above, right now the answer is 'no, it's not possible'.

We have a tracking issue at https://github.com/dotnet/roslyn/issues/57608. Feel free to thumbs up, or add your particular scenario to it which helps when it comes to prioritization.

Related