SHARE
TWEET

Untitled

a guest Jan 21st, 2018 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top