Visual Studio 2022 - implementing Using Source Generators in a .NET 6 Console Application
I keep running into I keep running into I'm performance testing and I'm trying to implement source generators in my .NET 6 console application using Visual Studio 2022... However, I'm working with issues where the generated code isn't recognized during compilation. I've set up a source generator project that outputs the generated code to a specific namespace, but it's like the main project doesn't see it. My source generator code looks like this: ```csharp [Generator] public class MySourceGenerator : ISourceGenerator { public void Initialize(GeneratorInitializationContext context) { } public void Execute(GeneratorExecutionContext context) { var sourceCode = @"namespace Generated { public class HelloWorld { public static string Greet() => \"Hello, World!\"; }}"; context.AddSource("HelloWorld.g.cs", sourceCode); } } ``` In my console application, I reference the generator project and try to use the generated class: ```csharp using Generated; class Program { static void Main(string[] args) { Console.WriteLine(HelloWorld.Greet()); } } ``` However, I receive the behavior: `CS0246: The type or namespace name 'Generated' could not be found` when I try to build the project. I've ensured that all necessary project references are set correctly and that the source generator project is built before the main application. I've also checked the build order and cleaned the solution multiple times. Is there something I'm missing in the setup? How can I ensure the generated code is recognized in my main application? My development environment is Linux. Am I missing something obvious? My development environment is Linux. How would you solve this? I'm working on a mobile app that needs to handle this. I'd be grateful for any help.