1

How do I find the full filepath of the assembly being analyzed by a C# source generator? I searched everywhere under context.SemanticModel.Compilation but I cannot find this information.

I am able to find the sources file location and the full file path of the referenced assemblies used by the assembly being analyzed but not the one of the assembly being analyzed!!

Can someone help?

Kilo7
  • 31
  • 3
  • 1
    Why do you need this? We don't make this available but there's a lot of surprises that would make it hard to use in some cases. – Jason Malinowski Oct 22 '21 at 18:27
  • @JasonMalinowski thanks for your feedback. The reason I needed this is because I introduced a number attributes that control the logic of my source generator. Rather than creating new models to collect the data about my attributes I wanted to create an instance of the attribute (using reflection) in the source generator (in an effort to increase code readability). My attribute required a type as an input parameter and this type is contained in the assembly that it about to be complied. As I said this cannot be done because the assembly I am generating code for is not yet compiled. – Kilo7 Oct 25 '21 at 07:57
  • Sounds like you worked out some of the complexities here! Even if the assembly was on disk, reflection is still problematic; reflection assumes your assembly can be loaded which isn't going always be the case too. Imagine you're building a project that deploys on a different platform or machine...reflection has issues there. – Jason Malinowski Nov 01 '21 at 18:51

1 Answers1

1

After posting the question I realized that this is not possible....and after describing the problem to a colleague I came to the realization that this is not provided because the assembly would not have been compiled yet.

Kilo7
  • 31
  • 3