我正在使用Microsoft.CSharp.CSharpCodeProvider以编程方式编译程序集&从外部.cs文件运行某些功能。编译单声道和-nostdlib
但是有没有办法禁止这些函数对文件系统进行任何更改等(我需要在某种类型的沙箱中运行它们)?
我正在考虑在CompilerParameters中添加“-nostdlib”选项,因此生成的程序集将无法访问System.IO.File和其他类。但我仍然需要System.Object的,System.ValueType等
现在我得到这些错误:
error CS0518: The predefined type `System.Object' is not defined or imported
error CS0518: The predefined type `System.ValueType' is not defined or imported
error CS0518: The predefined type `System.Attribute' is not defined or imported
error CS0518: The predefined type `System.Int32' is not defined or imported
... (too many of them)
我如何添加这些类,而那些会严重损害系统(如系统.IO.File,System.IO.Directory,System.Net。(something),System.Threading。(something)?)
或者,也许有更简单的方法?谢谢。