Is there an efficient way to Generate Folders using compiled-time source generator in c#?

249 views Asked by At

Compiled-time source generator for folders:

Is there an efficient way to make the Source Generators generate folders at compile time, not just files?

Note: I know that I can use System.IO, but I do not think that this is the best solution, and I prefer to write as follows:

context.AddSource(" folder /file.g.cs", "source");
  • I tried context.AddSource(" folder /file.g.cs", "source");

I expected that it would generate a folder named "folder" and inside it a file "file.g.cs" and this file contains the word "source" at compile time.

This will not work but will give an error message with the character number '\'.

  • I tried to deal with the files using the System.IO library, but because of this, the folder will not be modified at compile time, and it will not be added to the default path.
1

There are 1 answers

0
Mohamad Makkawi On BEST ANSWER

Based on the following GitHub conversation: Allow directories in source generator outputs , the solution to this problem is not in VS 17.5.2, so you will have to use VS 17.6 Preview