Reputation: 35873
IntelliSense gives errors because it disregards (does not see) the source generator generated source, despite build gives no errors.
I've tried to build/rebuild multiple times. The generated source are exist, and OK, I can navigate into them with ctrl + click and also the build gives no error.
Still the red underline and IntelliSense errors are there...
Question
What am I missing?
Upvotes: 4
Views: 1463
Reputation: 1236
Let me clarify the comment by @Hans Kesting , because I've recently been down this frustrating path:
There are typically multiple caches involved here.
One issue is that Visual Studio does not allow for analyzer assemblies to be unloaded once they are loaded. Once Visual Studio has loaded your analyzer for use in the IDE and Intellisense, it will keep using that version until you close Visual Studio, or at least until you increase the assembly version. However, when you hit build/rebuild for your project Visual Studio will spawn a new msbuild process which will (typically) load a fresh version of your analyzer. Thus you may end up with a project that builds fine but doesn't update the IDE and Intellisense.
Another cache issue concerns incremental builds with IIncrementalGenerator
. This newer version of the source generator will, if you play it right, cache the last execution and reuse the output for the IDE/Intellisense if nothing related has changed. This typically requires you to implement a custom equality comparer for the content of the source syntax node. However, if this comparison fails to take into account the relevant content (i.e. that which actually changed with the last keypress) the generator will not be executed and the IDE/Intellisense will not be updated. Again, msbuild may still run fine because each new build ignores any previous output cache and just feeds the analyzer every source node from the start.
Upvotes: 4