{"id":1732,"date":"2018-12-27T19:59:31","date_gmt":"2018-12-28T00:59:31","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=1732"},"modified":"2018-12-28T06:58:05","modified_gmt":"2018-12-28T11:58:05","slug":"calling-roslyn-from-net-framework-and-net-core","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2018\/12\/27\/calling-roslyn-from-net-framework-and-net-core\/","title":{"rendered":"Calling Roslyn from Net Framework and Net Core"},"content":{"rendered":"<p>It never ceases to amaze me how people can write a huge API and never bother to document how to use it. But, it&#8217;s been that way for as long as I can remember, going back 35 years. In\u00c2\u00a0my\u00c2\u00a0latest adventures, I&#8217;ve been trying to compile, link, and run C# code dynamically using Roslyn for <a href=\"https:\/\/github.com\/kaby76\/Piggy\">Piggy, my transformational system<\/a>. If you&#8217;ve ever used Roslyn in C#, you&#8217;ve probably discovered that it can be such a pain in the arse to\u00c2\u00a0use because <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/microsoft.codeanalysis?view=roslyn-dotnet\">Microsoft gives doc for the API<\/a>,\u00c2\u00a0<a href=\"https:\/\/github.com\/dotnet\/roslyn#get-started\">does give some tutorials<\/a>, but I can&#8217;t find a simple example for compiling, linking, and running C#. I don&#8217;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.<\/p>\n<p><!--more--><\/p>\n<p>After several days of trial and error hacking, I finally <a href=\"https:\/\/github.com\/kaby76\/RoslynCompileAndRun.\">wrote a solution to the compile\/link\/run problem<\/a>\u00c2\u00a0It works with both Net Core and Net Framework. The information is sort of out there (<a href=\"https:\/\/github.com\/dotnet\/roslyn\/wiki\/Runtime-code-generation-using-Roslyn-compilations-in-.NET-Core-App\">1<\/a>, <a href=\"https:\/\/github.com\/dotnet\/roslyn\/issues\/21205\">2<\/a>, <a href=\"https:\/\/luisfsgoncalves.wordpress.com\/2017\/03\/20\/referencing-system-assemblies-in-roslyn-compilations\/\">3<\/a>, <a href=\"https:\/\/www.codeproject.com\/Articles\/1215168\/Using-Roslyn-for-Compiling-Code-into-Separate-Net\">4<\/a>, and others), but it&#8217;s painful reading because it&#8217;s inaccurate, and doesn&#8217;t always work.<\/p>\n<p>Enjoy,\u00c2\u00a0Ken<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It never ceases to amaze me how people can write a huge API and never bother to document how to use it. But, it&#8217;s been that way for as long as I can remember, going back 35 years. In\u00c2\u00a0my\u00c2\u00a0latest adventures, I&#8217;ve been trying to compile, link, and run C# code dynamically using Roslyn for Piggy, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/165.227.223.229\/index.php\/2018\/12\/27\/calling-roslyn-from-net-framework-and-net-core\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Calling Roslyn from Net Framework and Net Core&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1732"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=1732"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1732\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=1732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=1732"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=1732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}