Я следую документации по генераторам исходного кода от Microsoft. Я создал библиотеку классов .NET Standard 2.0 и установил в качестве содержимого файла csproj следующее:
Код: Выделить всё
netstandard2.0
true
all
runtime; build; native; contentfiles; analyzers; buildtransitive
Код: Выделить всё
[Generator]
public class Sample : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
}
public void Initialize(GeneratorInitializationContext context)
{
}
}
Код: Выделить всё
[Generator]
public class Sample : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
context.AddSource("Foo.g.cs", "public class Bar { }");
}
public void Initialize(GeneratorInitializationContext context)
{
}
}
Код: Выделить всё
RS1035 The symbol 'GeneratorExecutionContext' is banned for use by analyzers: Non-incremental source generators should not be used, implement IIncrementalGenerator instead
Код: Выделить всё
[Generator]
public class Sample : IIncrementalGenerator
{
public void Execute(GeneratorExecutionContext context)
{
context.AddSource("Foo.g.cs", "public class Bar { }");
}
public void Initialize(IncrementalGeneratorInitializationContext context)
{
}
}
Как я могу решить эту проблему?
Подробнее здесь: https://stackoverflow.com/questions/791 ... eneratorex
Мобильная версия