C
C#ā€¢2w ago
Win

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.cs
GitHub
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
333fred
333fredā€¢2w ago
Have you written unit tests?
333fred
333fredā€¢2w ago
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
Win
Winā€¢2w ago
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.
333fred
333fredā€¢2w ago
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 found
Win
Winā€¢2w ago
Sorry, I didn't follow you. Where should I put the GetDiagnostics to?
333fred
333fredā€¢2w ago
The compilation
Win
Winā€¢2w ago
Oh, let me try.
333fred
333fredā€¢2w ago
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 compiler
Win
Winā€¢2w ago
Ahh, 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 it
What 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.
333fred
333fredā€¢2w ago
I generally recommend using the official testing SDK
Win
Winā€¢4d ago
Thanks. I will take a look at it. šŸ™ šŸ‘‹ I try it but I get stuck with version conflict error in test code
Dagger.SDK.Mod.SourceGenerator.Tests -> Dagger.SDK.Mod.SourceGenerator -> Microsoft.CodeAnalysis.CSharp 4.10.0 -> Microsoft.CodeAnalysis.Common (= 4.10.0)
Dagger.SDK.Mod.SourceGenerator.Tests -> Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing 1.1.2 -> Microsoft.CodeAnalysis.CSharp.Workspaces 3.8.0 -> Microsoft.CodeAnalysis.Common (= 3.8.0).
Dagger.SDK.Mod.SourceGenerator.Tests -> Dagger.SDK.Mod.SourceGenerator -> Microsoft.CodeAnalysis.CSharp 4.10.0 -> Microsoft.CodeAnalysis.Common (= 4.10.0)
Dagger.SDK.Mod.SourceGenerator.Tests -> Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing 1.1.2 -> Microsoft.CodeAnalysis.CSharp.Workspaces 3.8.0 -> Microsoft.CodeAnalysis.Common (= 3.8.0).
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?
333fred
333fredā€¢4d ago
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
Want results from more Discord servers?
Add your server
More Posts