Code Formatting in Roslyn SDK Preview

c#, roslyn

Solution

You can format `SyntaxNodes` using the `Microsoft.CodeAnalysis.Formatting.Formatter` like this (if you have a workspace):

using Microsoft.CodeAnalysis.Formatting;

var formattedResult = Formatter.Format(syntaxNode, workspace);

EDIT: As Jeroen wrote in a comment, if you don't have a workspace and don't need workspace-specific formatting settings, you can just create one:

var workspace = MSBuildWorkspace.Create();

Problem

In an earlier version (Roslyn CTP), I was using following code to format my generated code and it was working perfectly fine: ``` SyntaxNode.Format(FormattingOptions.GetDefaultOptions()).GetFormattedRoot() ``` With the new Roslyn version it no longer does, so what is the equivalent for the above code in the new version (SDK Preview)?

Original source