I'm creating a simple Roslyn Source Generator. The generator seems to work well in debug, correctly generating the desired class. However, when referencing it from another project in the solution, a red icon is shown near it with the "Ignored" tooltip and no output is produced:
The generator code is very simple:
namespace CompetencesSourceGenerator
{
using Microsoft.CodeAnalysis;
[Generator]
public class CompetenceNamesGenerator: CompetenceGeneratorBase
{
public override void Execute(GeneratorExecutionContext context)
{
context.AddSource(
"CompetenceNames.g.cs",
@"namespace Foo { public class Bar { } }"
);
}
}
}
I checked the following:
Microsoft.CodeAnalysis.CSharp
and Microsoft.CodeAnalysis.Analyzers
in generator project are up to dateWhy does it not work?
So apparently, the issue was caused by three factors, the combination of which resulted in a very confusing UX:
Worth mentioning that in Rider everything works just as expected, so I hope they fix this behavior in VS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.