roslyn-sdk icon indicating copy to clipboard operation
roslyn-sdk copied to clipboard

Unable to execute Generator with PackageReference

Open dansiegel opened this issue 4 years ago • 2 comments

Description

When including a PackageReference for a Generator that would normally be packed, the assembly reference is not copied into the execution directory when the Analyzer project is referenced from another project as a ProjectReference. I've attached a sample project that demonstrates the issue. You'll notice that the Generator project does set CopyLocalLockFileAssemblies to true.

sample-generator.zip

There are really two bugs that this exposes:

  1. When a generator is referenced from a local project dependencies are not being copied appropriately thus causing the generator to fail execution.
  2. If running from the CLI on a CLEAN build, you will see a warning that the Source Generation failed. If you run dotnet build again you will never again see the warning that Execution has failed. If running in Visual Studio you will never see the warning that execution has failed. This is likely due to Roslyn loading the project swallowing the error and then never showing the issue as it is a subsequent build.

dansiegel avatar May 26 '21 05:05 dansiegel

@chsienki should we move this over to roslyn? I think there is a general question of if we want source generators to work as project references. We currently include them in the examples but we are leading people into weird behavior down the line

jmarolf avatar May 26 '21 17:05 jmarolf

if it helps here... while I generally do not use Generators as a project reference for real projects... I do have some scenarios where it just makes running tests a heck of a lot easier to let the Generator do it's thing which in one case (works in combination with some Fody weavers) and this let's me better observe and test that the Generators and weavers are working together to do what I need them to do.

dansiegel avatar May 26 '21 18:05 dansiegel