Okno
Okno
CC#
Created by Okno on 1/3/2025 in #help
Compilation issue with source generator
Hello there, I am building a mapper source generator to learn Csharp. I am now testing it in a real project. Unfortunately using it as a dependency seems to trigger the following compilation error:
/usr/local/share/dotnet/sdk/8.0.402/Roslyn/Microsoft.CSharp.Core.targets(85,5): error MSB6006: "csc.dll" exited with code 1. [/Users/pauldelafosse/Code/di-business-meta-app/di-business-file-import/BusinessFileImport.Infrastructure.Persistence/BusinessFileImport.Infrastructure.Persistence.csproj]
/usr/local/share/dotnet/sdk/8.0.402/Roslyn/Microsoft.CSharp.Core.targets(85,5): error MSB6006: "csc.dll" exited with code 1. [/Users/pauldelafosse/Code/di-business-meta-app/di-business-file-import/BusinessFileImport.Infrastructure.Persistence/BusinessFileImport.Infrastructure.Persistence.csproj]
I have looked up this error code but I am really unsure what could be done to diagnose this. For reference the source generator repo is here: https://github.com/oknozor/CartographeAutomatique/tree/main Any advice on how to troubleshot this would be appreciated.
27 replies
CC#
Created by Okno on 12/18/2024 in #help
Source generator unable to resolve external type
I am writing a source generator to learn csharp and I stubbled into something strange. Here is the IncrementalValueProvider in my source generator:
var mapToPipeline = context.SyntaxProvider.ForAttributeWithMetadataName(
fullyQualifiedMetadataName: "CartographeAutomatique.MapToAttribute",
predicate: static (syntaxNode, _) => syntaxNode is TypeDeclarationSyntax,
transform: static (context, _) => PopulateTypeMapping(context, MappingKind.MapTo)
);
var mapToPipeline = context.SyntaxProvider.ForAttributeWithMetadataName(
fullyQualifiedMetadataName: "CartographeAutomatique.MapToAttribute",
predicate: static (syntaxNode, _) => syntaxNode is TypeDeclarationSyntax,
transform: static (context, _) => PopulateTypeMapping(context, MappingKind.MapTo)
);
It generate mapping code for a class A to a class B and is used like so:
[MapTo(typeof(Point3))]
public class Vector3
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
}
[MapTo(typeof(Point3))]
public class Vector3
{
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
}
Everything work as expected as long as the attribute parameter (here typeof(Point3))) is accessible in the current package. If the typeof attribute parameter lives in an external package the PopulateTyypeMapping method is never called by the IncrementalValueProvider`. I think I understand that the compiler is unable to resolve the class so it skip the attribute, but it's very puzzling that there is no error message or warning emitted at compile time. Am I missing something or is there a way to make this work without changing the attribute parameter to something else ?
24 replies