我写了一个非常简单的源代码生成器:
public void Execute(GeneratorExecutionContext context)
{
var sourceBuilder = new StringBuilder(@"
using System;
namespace Injector.ConsoleApp;
public partial class Program
{
static void HelloFrom(string name)
{
Console.WriteLine(""Hello from "" + name);
}
}
");
context.AddSource("helloWorldGenerator", SourceText.From(sourceBuilder.ToString(), Encoding.UTF8));
}
它的编译、运行和行为完全符合我的希望和期望,但是......
Visual Studio 不知道生成的函数并显示 CS0103 错误。我怎样才能让 VS 不为此显示错误?