Calling Roslyn from Net Framework and Net Core

It never ceases to amaze me how people can write a huge API and never bother to document how to use it. But, it’s been that way for as long as I can remember, going back 35 years. In my latest adventures, I’ve been trying to compile, link, and run C# code dynamically using Roslyn for Piggy, my transformational system. If you’ve ever used Roslyn in C#, you’ve probably discovered that it can be such a pain in the arse to use because Microsoft gives doc for the APIdoes give some tutorials, but I can’t find a simple example for compiling, linking, and running C#. I don’t need to know all the details yet, just a starting point framework. Unfortunately, the solution is quite sensitive to whether you use Net Core or Net Framework.

After several days of trial and error hacking, I finally wrote a solution to the compile/link/run problem It works with both Net Core and Net Framework. The information is sort of out there (1, 2, 3, 4, and others), but it’s painful reading because it’s inaccurate, and doesn’t always work.

Enjoy, Ken

Posted in Tip