Skip to content

Compiling (and caching) to a .dll

Adam Ralph edited this page Mar 1, 2015 · 2 revisions

Let's assume we have a file named server.csx. By default when you run scriptcs with no additional parameters scriptcs server.csx, your .csx file is compiled and executed in memory.

If you are always running the same code, this takes more time than necessary since a new compilation always takes place.

The -cache flag

We have introduced the -cache flag, which allows you to compile to a .dll once and use it to avoid unnecessary builds when no changes have been performed. You can take advantage of this feature by invoking scriptcs server.csx -cache.

The .dll files are written to a hidden .scriptcs_cache directory. At the time of writing (December 4th, 2013) when you provide the -cache flag, a check is performed to see if a file named %scriptFileName%.dll exists inside a .scriptcs_cache folder located in the current working directory. In this case, the check would be for server.dll.

  • If the assembly exists, it is automatically loaded and the script is executed.
  • If the assembly does not exist:
    1. Compile the script into a .dll.
    2. Write the .dll to the .scriptcs_cache directory.
    3. Execute the script.

Flushing the cache

As you probably deduced after reading how the feature works, you will need to manually delete the .dll inside the .scriptcs_cache folder (or the .scriptcs_cache folder altogether) if you perform changes to your .csx files and want them compiled into a .dll.

Future improvements

There is still a long way to go, but we are working on this. The idea is to detect if any of the cached .dll dependencies (.dll or .csx files) have changed since it was created.