Probably a simple learning issue, but I'm attempting to use the new roslyn source generators to automatically generate some source code for .net framework 4.7.2 (mvc is the goal, but I'll be happy if it worked in my test console app).
Here's my code
[Generator]
public class GenerateCommand : ISourceGenerator
{
public const string TestCode = @"
namespace Test
{
public static class Hello
{
public static string World = ""Hi from generated code."";
}
}";
public void Initialize(InitializationContext context) { }
public void Execute(SourceGeneratorContext context)
{
context.AddSource("Hint_Hello_World", SourceText.From(TestCode, Encoding.UTF8));
}
public void Test()
{
var x = Test.Hello.World; // <-- Refuses to build.
}
}
}
Package versions are Microsoft.CodeAnalysis.CSharp v 3.7.0 (and associated roslyn stuff)
This seems to be about as simple as I can make it and it seems to work if I'm targeting .net core, it's just when I'm trying to add it to a framework project that it does nothing. No errors, no output messages, just not running or generating source.
Any help would be appreciated.