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:
- Generator project targets .NET Standard 2.0
- Referencing project targets .NET 6
- Both
Microsoft.CodeAnalysis.CSharp
andMicrosoft.CodeAnalysis.Analyzers
in generator project are up to date - VS is up to date (17.4.4)
- .NET Compiler Platform SDK is installed
Why does it not work?
<ProjectReference Include="..\relativepathhere\CompetencesSourceGenerator.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
might work? emphasis on the extra attributes there – Haga.g.cs
file is not updated and you cannot actually see the current compilable source. Is this a known issue? – Haver