Ich folge der Dokumentation zu Source Generators von Microsoft. Ich habe eine .NET Standard 2.0-Klassenbibliothek erstellt und Folgendes als Inhalt der csproj-Datei festgelegt:
Code: Select all
netstandard2.0
true
all
runtime; build; native; contentfiles; analyzers; buildtransitive
Code: Select all
[Generator]
public class Sample : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
}
public void Initialize(GeneratorInitializationContext context)
{
}
}
Code: Select all
[Generator]
public class Sample : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
context.AddSource("Foo.g.cs", "public class Bar { }");
}
public void Initialize(GeneratorInitializationContext context)
{
}
}
Code: Select all
RS1035 The symbol 'GeneratorExecutionContext' is banned for use by analyzers: Non-incremental source generators should not be used, implement IIncrementalGenerator instead
Mobile version