AIUI, transitive references are an MSBuild rather than a Roslyn feature, and are to do with Package/ProjectReferences rather than assembly references. I believe the compiler just gets a set of assembly references supplied to it and no information about where they came from. As a result, I don't see any way to distinguish between direct and transitive references from within an analyzer or source generator (i.e. given a CodeAnalysis.Compilation object). Compilation.References includes the transitive ones, as does Compilation.ReferencedAssemblyNames.
Does anybody know a way to get at this information? Is it possible to get hold of an MsBuild Project object, from which it could be gleaned?