Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. var workspace = MSBuildWorkspace.Create();
  2. var project = workspace.OpenProjectAsync(@"path\to\.csproj").Result;
  3.  
  4. var documents = project.DocumentIds;
  5. foreach (var documentId in documents)
  6. {
  7.     var document = project.GetDocument(documentId);
  8.     var root = document.GetSyntaxRootAsync().Result
  9.  
  10.     var rewrite = new MyRewrite();
  11.     root = rewrite.Visit(root);
  12.  
  13.     var newDocument = document.WithSyntaxRoot(root);
  14.     var compilation = newDocument.Project.GetCompilationAsync().Result;
  15.  
  16.     // When I look at the sementatic model here it contains my changes.
  17.     var sementaticModel =
  18.     compilation.GetSemanticModel(newDocument.GetSyntaxTreeAsync().Result);
  19.  
  20.     // But when I inspect this dll with dotPeek it's still the old code without changes.
  21.     compilation.Emit("new/dll/path");  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement