Trying to change and compile code in a MsBuildWorkspace (roslyn)

I’m playing around with Roslyn and trying to make a simple example where i:

  1. Load a .csproj
  2. Make some minor change to the code (currently I just replace some stuff)
  3. Compile the changed project to memory or a new dll.

So far 1 and 2 is done but I’m having some problems with the compile part. If I compile it to a new dll and inspect it (with dotPeek) it doesn’t have my new changes. It’s simply the orginal code.

My current code look like this: https://pastebin.com/eFEYbLqA

Anyone with Roslyn experience that can point me in the right direction? Maybe I just missunderstand the “emit” method, because it say “Emit the IL for the compiled source..”. So maybe I need to compile it some other way first?

submitted by /u/Meeii
[link] [comments]

Leave a Reply