title: Applying multiple changes to a solution in roslyn
body: <p>I want to apply changes to several documents of a solution but only the first change is reflected and rest of them are rejected.<a href="http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis.Workspaces/Workspace/Workspace.cs,7d9370f0e9961b4c,references" rel="noreferrer">This</a> link shows how only once can changes be applied to a solution. What would be a work around for this. I would appreciate a link directing to a solution or a code snippet.</p>
  
  <p>Here is my function : </p>
  
  <pre><code>public static async Task&lt;bool&gt; AddMethod(string solutionPath)
  {
      var workspace = MSBuildWorkspace.Create(); 
      var solution = await workspace.OpenSolutionAsync(solutionPath);
      ClassDeclarationSyntax cls = SyntaxFactory.ClassDeclaration("someclass");
  
      foreach (var project in solution.Projects)
      {
          foreach(var document in project.Documents)
          {
              Document doc = project.GetDocument(document.Id);
              var root = await doc.GetSyntaxRootAsync();
              var classes = root.DescendantNodes().Where(n =&gt; n.IsKind(SyntaxKind.ClassDeclaration));
              if (classes.Count() != 0)
              {
                  SyntaxNode FirstClass = classes.First() as ClassDeclarationSyntax;
                  if (FirstClass != null)
                  {
                      var newRoot = root.ReplaceNode(FirstClass, cls);
                      doc = doc.WithText(newRoot.GetText());
                      Project proj = doc.Project;
                      var abc = workspace.TryApplyChanges(proj.Solution);
                  }
              }
          }
      }
      return true;
  }
  </code></pre>