/// <summary> /// Gets the debug output path for the specified class name. /// </summary> /// <param name="context">The current generator context.</param> /// <param name="name">The source file name without extension.</param> /// <returns>The generated debug output path for the given source file.</returns> public static string GetGeneratedDebugSourcePath(this GeneratorExecutionContext context, string name) { var path = Path.Combine(context.GetGeneratedDebugPath(), context.Compilation.Assembly.Name); Directory.CreateDirectory(path); return(Path.Combine(path, $"{name}.g.cs")); }
public static void LogInfo(this GeneratorExecutionContext context, string message) { // Ignore IO exceptions in case there is already a lock, could use a named mutex but don't want to eat the performance cost try { var path = Path.Combine(context.GetGeneratedDebugPath(), "SourceGen.log"); using (var w = File.AppendText(path)) w.WriteLine(message); } catch (IOException) { } }