在程序运行的外部C#文件文件、程序

2023-09-04 11:28:03 作者:不吻不泪

请问NET框架有任何类,允许你运行(编译除preT或其他)外部脚本文件中包含C#code?

Does the .NET framework have any classes which allow you to run (compile, interpret or whatever) an external script file containing C# code?

举例来说,如果我有一个文件 hello.cs中包含这样的:

For instance, if I have a file Hello.cs containing this:

class Hello
//This program displays Hello World
{
    static public void Main()
    {
        System.Console.WriteLine("Hello World");
    }
}

我怎样才能加载code以上,从一个WinForm的,应用程序,并执行它?

how can i load the code above, from within a winform, app and execute it?

我感兴趣的负载/执行逻辑;该程序可以是任何东西,从一个控制台应用程序到另一个winform应用程序。

I'm interested in the load/execute logic; the program could be anything, from a console app to another winform app.

反思是否允许这样?

推荐答案

看看下面的文章:的 C#:写上使用即时编译扩展的应用程序

Check out the following article: C#: Writing extendable applications using on-the-fly compilation.