Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source Generator: information about referencing project?

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?

like image 889
ChristianMurschall Avatar asked Jul 31 '26 05:07

ChristianMurschall


1 Answers

I ended up using:

public void Execute(GeneratorExecutionContext context) {
     var mainSyntaxTree = context.Compilation.SyntaxTrees
                          .First(x => x.HasCompilationUnitRoot);

     var directory = Path.GetDirectoryName(mainSyntaxTree.FilePath);
like image 165
ChristianMurschall Avatar answered Aug 01 '26 17:08

ChristianMurschall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!