我正在使用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)?)
或者,也許有更簡單的方法?謝謝。