<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Compiler on queil.net</title>
    <link>https://queil.net/tags/compiler/</link>
    <description>Recent content in Compiler on queil.net</description>
    <generator>Hugo</generator>
    <language>en-uk</language>
    <lastBuildDate>Fri, 04 Jun 2021 08:52:26 +0100</lastBuildDate>
    <atom:link href="https://queil.net/tags/compiler/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Embedding F# Compiler: NuGet References</title>
      <link>https://queil.net/2021/06/embedding-fsharp-compiler-nuget-references/</link>
      <pubDate>Fri, 04 Jun 2021 08:52:26 +0100</pubDate>
      <guid>https://queil.net/2021/06/embedding-fsharp-compiler-nuget-references/</guid>
      <description>&lt;p&gt;UPDATE: If you are looking for a ready to use solution please check out my &lt;a href=&#34;https://github.com/queil/fsc-host&#34;&gt;fsc-host&lt;/a&gt; NuGet package. Also I wrote a &lt;a href=&#34;https://queil.net/2021/10/embedding-fsharp-compiler-fsc-host-nuget/&#34;&gt;blog post&lt;/a&gt; about it.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;intro&#34; class=&#34;anchor-link&#34;&gt;&lt;a href=&#34;#intro&#34;&gt;Intro&lt;span class=&#34;pilcrow&#34;&gt;&amp;nbsp;¶&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;In the &lt;a href=&#34;https://queil.net/2021/05/embedding-fsharp-compiler/&#34;&gt;previous post&lt;/a&gt; I showed how to extend an F# application with scripting capabilities. This time I want to extend the previous example with the &lt;a href=&#34;https://docs.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/#referencing-packages-in-f-interactive&#34;&gt;#r directive&lt;/a&gt; support and resolving NuGet dependencies.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;how-to&#34; class=&#34;anchor-link&#34;&gt;&lt;a href=&#34;#how-to&#34;&gt;How to&lt;span class=&#34;pilcrow&#34;&gt;&amp;nbsp;¶&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;On high level we need to extract NuGet packages information from the script and pass it to the compiler as additional arguments. Before compiling we also need to dynamically load the referenced dlls to the host application. I first took the naive approach of parsing and extracting the directives from AST and feeding them into &lt;code&gt;FSharpDependencyManager&lt;/code&gt;. It worked to an extent. Luckily, &lt;code&gt;FsChecker&lt;/code&gt; comes with a built-in solution. We can use &lt;code&gt;GetProjectOptionsFromScript&lt;/code&gt; and subsequently &lt;code&gt;ParseAndCheckProject&lt;/code&gt; methods. That way we can retrieve &lt;code&gt;DependencyFiles&lt;/code&gt; and extract resolved dlls&amp;rsquo; paths.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Embedding F# Compiler</title>
      <link>https://queil.net/2021/05/embedding-fsharp-compiler/</link>
      <pubDate>Sat, 29 May 2021 10:03:24 +0100</pubDate>
      <guid>https://queil.net/2021/05/embedding-fsharp-compiler/</guid>
      <description>&lt;p&gt;UPDATE: If you are looking for a ready to use solution please check out my &lt;a href=&#34;https://github.com/queil/fsc-host&#34;&gt;fsc-host&lt;/a&gt; NuGet package. Also I wrote a &lt;a href=&#34;https://queil.net/2021/10/embedding-fsharp-compiler-fsc-host-nuget/&#34;&gt;blog post&lt;/a&gt; about it.&lt;/p&gt;&#xA;&#xA;&lt;h2 id=&#34;motivation&#34; class=&#34;anchor-link&#34;&gt;&lt;a href=&#34;#motivation&#34;&gt;Motivation&lt;span class=&#34;pilcrow&#34;&gt;&amp;nbsp;¶&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;Embedded scripting is one of the ways of providing flexibility to compiled applications. It is not free from problems (performance penalty, security issues, additional tooling is required). But if your goal is a ceremony-free flexibility for the end-user then scripting is a very robust way&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; . F# comes with great capabilities in this area. I want to show you how you can extend your otherwise statically compiled program with scripting.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
