Skip to content

Hosting on .NET Framework

Oleg Shilo edited this page Feb 9, 2026 · 4 revisions

A useful read about CS-Script evolution path from .NET Framework to .NET: .NET Framework to .NET transition

Overview

The CS-Script is developed on and for the latest .NET. Meaning that it primarily targets .NET Core family in both CLI Script Execution and Hosted Script Execution.

However, since the CS-Script class library NuGet package is compiled against .NET Standard, it makes it possible to host even on the older runtime versions, such as .NET Framework.

Note, hosting on .NET Framework is possible, and it can even allow using scripts of the latest versions of C# syntax. However, such scenarios are not the major intended use, thus their support is somewhat limited. For the full-fledged support, you will need to use CS-Script.net-framework, which was specifically designed for that. Though it's no longer actively maintained as well as the .NET Framework itself.

How To?

The steps required for hosting CS-Script in a .NET Framework application are not very different compared to hosting on .NET:

  1. Add CS-Script package
  2. Add your scripting code. IE:
dynamic script = CSScript.RoslynEvaluator
                         .LoadMethod(@"public (int, int) func()
                                       {
                                           return (0,5);
                                       }");

(int, int) result = script.func();

int sum = CSScript.RoslynEvaluator.Eval("6 + 3");

There are two code samples that show you various scripting scenarios available on .NET Framework CLR:

Both samples also demonstrate how enable support for the latest C# syntax for CodeDom by dynamically downloading the required version of the CodeDom engine. The default one (present on any Windows edition) can only compile against C#7.3.

The samples in the repository are part of the complete Visual Studio solution, so they reference CS-Script as a project. But you will need to reference it as a NuGet package (see step one above). This is a stand-alone sample that was prepared as part of the support for #434: Sample.zip

Limitations

  • The .NET Framework support is only guaranteed for the CS-Script package itself, but not for its dependencies. CS-Script NuGet package is compiled against netstandard2.0, so it can be hosted on any edition of .NET. However, its dependency packages (e.g. Microsoft.CodeAnalysis) may or may not be available for your exact hosting application runtime. And this is fully controlled by the dependencies' vendors. Ie, the code samples in the repos stopped working in 2024 (after dependency updates) and then started working again in 2025 without any changes in the sample code. Only the package updates to the latest versions.
  • The latest version of C# is not supported out-of-the-box since MS stopped updating .NET Framework a long time ago. While the samples show the workaround, it does not feel as natural as one would want it to be.
  • Some legacy API from early CS-Script pre-.NET Core versions is no longer available since it has no equivalent in .NET Core family.

Clone this wiki locally