Incremental source generators with Collect(): what determines target assembly?

109 views Asked by At

Say we have an incremental source generator like this:

    public override void Initialize(IncrementalGeneratorInitializationContext context)
    {
        var provider = context.SyntaxProvider.CreateSyntaxProvider(FilterSyntaxNode, TransformSyntaxNode)
            .Where(model => model is not null)
            .Collect();

        context.RegisterSourceOutput(provider, GenerateSource!);
    }

Due to the call to Collect(), GenerateSource needs to accept an ImmutableArray<TModel> instead of just a single TModel.

Now consider the following assembly structure:

  • Project Application references project Domain
  • Project Domain references the source generator package

When working with a generator that does not Collect(), the generated code belongs to the assembly that its input resides in. So source generated based on types from Domain ends up in Domain, and source generated based on types from Application end up in that assembly. Great.

How is the target assembly determined when multiple inputs from different assemblies are combined with Collect()?

0

There are 0 answers