'Can a Source Generator tell if its being run for editor support (IntelliSense) or as part of an actual build?
My source generator needs to write some files to disk in addition to generating code files for the compilation in progress. These disk writes are completely unnecessary when the generator is being run by the IDE for its IntelliSense (or equivalent) functionality and only makes sense when the project is being actually built (it even tends to cause some failures, the IDE loves to run multiple instances of the source generator simultaneously).
Additionally, I see no reason to generate actual internals of any of the types generated by the source generator. Intuitively, only generating the public surface for the generated types would be lead to a faster and more responsive editor experience.
What is the most robust way for the source generator to differentiate what purpose it is being run for?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
