Open DoctorVanGogh opened 11 months ago
Well, I should probably actually attach that demo solution 😅
Same problem, wait for an answer
Are you saying the sources are not emitted during design time builds but are emitted otherwise? That sounds like by design behavior.
Version Used: Visual Studio 17.6.5
Steps to Reproduce:
Compile the attached demo solution. It contains & uses a "simple" incremental source generator which will output a
Foo.generated.cs
file that contains a classBar
which has astatic void <..>() {}
method for each line fromBar.txt
where the text of the line is used as method names. Current lines arex
,y
&z
. The text from the line is repeated for the method name as many times as theRepeats
metadata on theAdditionalFiles
item for theBar.txt
file. InitialRepeats
value is 3, so the generated class will look like:The source generator consuming project has definitions of
to output the generated source to a defined location.
Expected Behavior: Compilation and emit of generated source to the file system in the defined subfolder
GeneratedSource
.Actual Behavior: Compilation, creation of the
Post (re)build:
![image](https://github.com/dotnet/roslyn/assets/324067/7fc4c8ba-9da1-45c7-b0a0-c0e357523a0e)
GeneratedSource
folder (which is initially "missing") but no persisted source files in that folder: Pre compilation:Additional observations The generated source is correctly displayed in the "Dependencies/Analyzers" node(s):![image](https://github.com/dotnet/roslyn/assets/324067/d76ef5a1-c649-4120-86f8-26e8b2f4ba36)
The complete lack of persistent emits is a tad baffling, since I have another generator where emit on (re)build works just fine. 🤷 What I did observe though, was that emits do never work on
DesignTimeBuild
s:proj
file (typically yourcsproj
, here an importedAnalyzerClient.proj
) in a split view:Repeats
value from3
to any other value (example1
). Save the editedproj
file. This will trigger aDesignTimeBuild
:I have never been able to get an emit to work on design time builds. It always needed a rebuild for emits to work.
This can be quite confusing if you have set up your source generator to react to specific changes in attributes, have included your emitted source in a project and the internal intellisense state (and subsequent compilations) will reflect changes to those attributes, but your "on disc" source will not.