I have some C# code that accepts a script written in C# itself and executes the script dynamically. I am able to make use of built in libraries by referencing their assemblies as shown below.
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Data.dll")
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
cp.ReferencedAssemblies.Add("System.Linq.dll");
cp.ReferencedAssemblies.Add("System.Xml.Linq.dll");
cp.ReferencedAssemblies.Add("System.Core.dll");
cp.ReferencedAssemblies.Add("System.Net.Http.dll");
...
options.GenerateExecutable = false;
options.GenerateInMemory = true;
CompilerResults results = provider.CompileAssemblyFromSource(options, "<SCRIPT-SOURCE-HERE>");
However, when trying to add an additional library that is not part of the .NET Framework I run into problems. Here I have added the RestSharp
library to the project via NuGet
and I can confirm that the RestSharp.dll is in the bin
directory of the project.
options.ReferencedAssemblies.Add("RestSharp.dll");
I add this to the script I am attempting to compile ...
using RestSharp;
However when trying to compile the script that makes use of the RestSharp
library I receive an error ...
Metadata file 'RestSharp.dll' could not be found
What is the best way to refer to the RestSharp
assembly?