IssueRaiser

Support generating non-source files

We have a few use cases where we'd like to leverage source generators to produce non-source files. Basically, we want to use source generators to generate secondary build outputs. For example: * We annotate data models with data classification attributes to denote PII and we produce a CSV file that enumerates the types and members in the project and their data classification. You can then take this CSV file and use it when doing privacy audits. * We use source generators to produce a bunch of code around metrics. We'd like to emit a schema file describing the effective shape of the metrics being produced by the code. This would probably be in the form of an output JSON file. We have a few other scenarios in the wings which could leverage this approach. Unfortunately, source generation is currently limited to C# sources. Trying to emit files with other extensions doesn't work. As a result, our source generator currently contains this horrible hack: ```csharp public void Execute(GeneratorExecutionContext context) { ... generate the CSV file ... context.CancellationToken.ThrowIfCancellationRequested(); /// Adding the workaround to generate reports via File writes since <see cref="GeneratorExecutionContext.AddSource(string, CodeAnalysis.Text.SourceText)"/> /// has an underlying check for `.cs` files and automatically adds the `.cs` suffix if the provided filename has some other filetype. /// Refer

Posted by geeknoid on Nov 5, 2021, 10:05 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

support (Other)

Support generating non-source files

geeknoidNov 5, 2021, 10:05 PM

We have a few use cases where we'd like to leverage source generators to produce non-source files. Basically, we want to use source generators to generate secondary build outputs. For example: * We annotate data models with data classification attributes to denote PII and we produce a CSV file that enumerates the types and members in the project and their data classification. You can then take this CSV file and use it when doing privacy audits. * We use source generators to produce a bunch of code around metrics. We'd like to emit a schema file describing the effective shape of the metrics being produced by the code. This would probably be in the form of an output JSON file. We have a few other scenarios in the wings which could leverage this approach. Unfortunately, source generation is currently limited to C# sources. Trying to emit files with other extensions doesn't work. As a result, our source generator currently contains this horrible hack: ```csharp public void Execute(GeneratorExecutionContext context) { ... generate the CSV file ... context.CancellationToken.ThrowIfCancellationRequested(); /// Adding the workaround to generate reports via File writes since <see cref="GeneratorExecutionContext.AddSource(string, CodeAnalysis.Text.SourceText)"/> /// has an underlying check for `.cs` files and automatically adds the `.cs` suffix if the provided filename has some other filetype. /// Refer

Comments (0)

No comments yet. Start the discussion.

Comment on this issue