Open otac0n opened 1 year ago
Note that the only debugging strategy I would recommend for source generators is writing a unit test with the source generator testing library and debugging the unit test.
@sharwell I am also seeing an issue when building a test project as you suggested.
Target CoreCompile:
2> CompilerServer: server failed - server rejected the request due to analyzer / generator issues 'analyzer assembly 'C:\Users\otac0n\Projects\Weave\Weave\bin\Debug\net461\Weave.exe' has MVID 'aa714b17-ce2c-4978-913b-7efc5ff79beb' but loaded assembly 'C:\Users\otac0n\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\bad8135ebc01479e82c10d3755f6f265\1\Weave.exe' has MVID '27c27310-b0ad-4715-a51c-efba8778c534'' - c4784ddc-e1b8-4469-9bcc-787c333778eb
I am multi-targeting, sure. But analyzers can only come from netstandard2.0. It makes no sense for this to be the analyzer assembly reference found (even though my test project is set to net461 at the moment.)
I think this is a bug.
Seems like this is about a half a workaround:
<ProjectReference Include="..\Weave\Weave.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" SetTargetFramework="TargetFramework=netstandard2.0" />
I have to manually reference MSBuild files and etc. from my package project (which would be provided via NuGet normally), which feels like a medium-sized oversight as well.
<PropertyGroup>
<WeaveAssemblyPath>$(MSBuildThisFileDirectory)..\Weave\bin\$(Configuration)\net461\Weave.exe</WeaveAssemblyPath>
</PropertyGroup>
<Import Project="..\Weave\Weave.targets" />
I am multi-targeting my templating library Weave and have had to workaround what appears to be a bug in the debug launch profile for source generators.
You can find a repro case here: https://github.com/otac0n/Weave/tree/feature-source-generators c49ef389
This workaround is (currently) working for debugging:
However, I will also report that the behavior of the workaround is quite stange. It is not enough to make that change on the filesystem and debug, or even to restart Visual Studio. I found that I actually had to interact with the Project Settings dialog:
This may be a clue, or it may be aggressive caching that is unrelated.
Visual Studio Details: