主要是使用CSScript这个库。nuget上可以选netcore版本的。这个库已经存在很久了。之前在netframework上就用过,不错。(效率没测试,只是实现了我需要的功能)

1 引用 using CSScriptLib;

2 调用
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.Roslyn;
var al= Assembly.LoadFrom(@"F:\gitcode\DynamicPlugin\csst\bin\Debug\netcoreapp3.1\Bll.dll");

        dynamic script = CSScript.RoslynEvaluator.ReferenceAssembly("System.ValueTuple")
                                 .ReferenceAssembly(al)
                                 .LoadMethod(@"string  Hello()
                                               {
                                                 
                                                      
                                                       return Bll.op.GetName();
                                               
                                                   
                                               }");

       var a= script.Hello(); //返回wxq

3 bll的代码(bll是一个新的项目,只有一个文件op.cs)

using System;
using System.Collections.Generic;
using System.Text;

namespace Bll
{
public class op
{

    public static string GetName() {
        return "wxq";
    }

}

}

4 文档地址 https://www.cs-script.net/cs-script/help-legacy/root/

另github上有源码。搜索cs-script .

netcore的地址 https://github.com/oleg-shilo/cs-script.core

原始版本 https://github.com/oleg-shilo/cs-script

相关文章:

  • 2022-12-23
  • 2021-08-06
  • 2021-05-31
  • 2021-10-15
  • 2022-12-23
  • 2021-06-09
猜你喜欢
  • 2022-01-20
  • 2022-01-09
  • 2021-09-22
  • 2021-06-27
相关资源
相似解决方案