C#Roslyn执行

时间:2014-09-07 08:39:53

标签: c# execute roslyn

using Roslyn.Compilers;
using Roslyn.Scripting.CSharp;

ScriptEngine scriptEngine = new ScriptEngine();
try
{
    object result = scriptEngine.Execute(txtSource.Text);
    txtOutput.Text = result + "";
}
catch (Exception ex)
{
    txtOutput.Text = ex.Message;
}
  

错误1'Roslyn.Scripting.CSharp.ScriptEngine'不包含'Execute'的定义,也没有扩展方法'Execute'接受'Roslyn.Scripting.CSharp.ScriptEngine'类型的第一个参数   可以找到(你错过了使用指令或程序集引用吗?)

1 个答案:

答案 0 :(得分:0)

 var engine = new ScriptEngine();
 var session = engine.CreateSession();            
 var result = session.Execute("1+1");