✅ Is there a way to programmatically formatt a file

Im writing a transpiler to C# (in C#) and I would like to formatt the output files after I write them to C# does anybody know how to do this? Roslyn does not work:
        private async void FormatCode(string path)
        {
            
            string code = File.ReadAllText(path);
            SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code);
            var root = await syntaxTree.GetRootAsync();
            var formattedRoot = Formatter.Format(root, Formatter.Annotation, new AdhocWorkspace());
            string formattedCode = formattedRoot.ToFullString();
            File.WriteAllText(path, formattedCode);
        }

SOLUTION FOUND by SleepWellPupper
Was this page helpful?