Source generator WithAttributeMetadataName transform function not get invoke
Hi, first time on C# here.
I try to generate a partial class for any class that annotate with attribute. I see that source generator has
WithAttributeMetadataName
to find the node that has attribute. I found out that I my code generator didn't get generate, so I debug the generator code and found out that the transform
doesn't get invoke. What am I wrong with the provider setup? š¢
My code is here https://github.com/wingyplus/dagger-dotnet-sdk/blob/d1e042de19777f1c0f0fcc0737e565e4809756bc/sdk/Dagger.SDK.Mod.SourceGenerator/SourceGenerator.csGitHub
dagger-dotnet-sdk/sdk/Dagger.SDK.Mod.SourceGenerator/SourceGenerato...
Dagger DotNet SDK. Contribute to wingyplus/dagger-dotnet-sdk development by creating an account on GitHub.
14 Replies
Have you written unit tests?
GitHub
dagger-dotnet-sdk/sdk/Dagger.SDK.Mod.SourceGenerator.Tests/SourceGe...
Dagger DotNet SDK. Contribute to wingyplus/dagger-dotnet-sdk development by creating an account on GitHub.
Have you verified that the code actually compiles? For example, I don't see where you're providing the definition of
Dagger.SDK.Mod.ObjectAttribute
I declared it here https://github.com/wingyplus/dagger-dotnet-sdk/blob/d1e042de19777f1c0f0fcc0737e565e4809756bc/sdk/Dagger.SDK.Mod/Attributes.cs
GitHub
dagger-dotnet-sdk/sdk/Dagger.SDK.Mod/Attributes.cs at d1e042de19777...
Dagger DotNet SDK. Contribute to wingyplus/dagger-dotnet-sdk development by creating an account on GitHub.
Where are you providing that to your test though?
This is really another example of where I don't like the
Verify
framework: nothing is verifying that your code has no other errors in it
I'd be willing to bet that, if you were to call GetDiagnostics
on the compilation, you'd get an error that ObjectAttribute
wasn't foundSorry, I didn't follow you. Where should I put the
GetDiagnostics
to?The compilation
Oh, let me try.
https://github.com/wingyplus/dagger-dotnet-sdk/pull/7/files#diff-4074c63e648aa9325c7fce423c19505a9b31b9af880afcbf8b972645accd8106R89
Not sure what
Binder
is in this case, but you're also not providing any of the basic reference assemblies for the runtime
If you're going to manually construct compilations like this, I would highly recommend using https://github.com/jaredpar/basic-reference-assemblies to get the references to pass to the compilerAhh, after put
ReferenceAssemblies.Netstandard20
the diagnostics get reduced. š
So I do need to find the way to reference Dagger.SDK.Mod
to the refences to make c# compilation understand it right?
This is really another example of where I don't like the Verify framework: nothing is verifying that your code has no other errors in itWhat is the preferred way to test this? I just don't want to fight with indentation in string. So I think of the snapshot testing at first.
I generally recommend using the official testing SDK
Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing 1.1.2
Roslyn Source Generator Framework C# Types.
Thanks. I will take a look at it. š
š
I try it but I get stuck with version conflict error in test code
The sourcegenerators testing library is currently rely on code analysis common version 3.8 while my real code
Dagger.SDK.Mod.SourceGenerator
are using csharp code analysis which's rely on cod analysis common 4.10. It seems those libraries version are not align. How do I fix it?Explicitly reference
Microsoft.CodeAnalysis.CSharp 4.10
in your tests
The framework is designed to work with many different versions of roslyn, so this is a common thing that can happen