I started playing with the C# source generators.
What I want is to kick off a git describe --tags --long process and populate a static GitVersion class with the current tag and hash code as properties.
The problem is, that I have no information about the directory of the referencing project so I cannot know where to run the git process.
I cannot find any useful information in the GeneratorExecutionContext argument of the Execute function.
AppDomain.CurrentDomain points to the csc.exe process so I guess there is no way to know it's there?
I ended up using:
public void Execute(GeneratorExecutionContext context) {
var mainSyntaxTree = context.Compilation.SyntaxTrees
.First(x => x.HasCompilationUnitRoot);
var directory = Path.GetDirectoryName(mainSyntaxTree.FilePath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With