c# - 使用 C# 运行 VBScript

标签 c# vbscript reference

我正在尝试在 C# 类库项目中执行用 VBScript 编写的脚本

using System.Web.UI;  //reference added at top

MSScriptControl script = new ScriptControl();
script.Language = "VBScript";
script.AddObject("Repository", connectToDB.GetRepository);  

我收到以下编译错误:

Error CS0246: The type or namespace name 'MSScriptControl' could not be found (are you missing a using directive or an assembly reference?)

有什么想法吗?

最佳答案

  1. 将“Microsoft Script Control 1.0”的 COM 引用添加到您的项目中。
  2. 使用 Microsoft.VisualBasic;
  3. 使用此代码:​​

    MSScriptControl.ScriptControl script = new MSScriptControl.ScriptControl();
    script.Language = "VBScript";
    script.AddObject("Repository", connectToDB.GetRepository); 
    

关于c# - 使用 C# 运行 VBScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24909717/

相关文章:

c# - C#读写txt文件发布问题

c# - 将 HTML 动态添加到 ASP.NET 页面

c# - true 而不是 True (C#)

shell - 使用 VBScript 启动应用程序

windows-7 - Bat 文件在我的桌面上创建 Windows 7 快捷方式.lnk

sql - 使用 A999 > A1000 解决下一个最大问题

c# - 将结构从 C++ 转换为 C#

c++ - 指向类的成员函数的指针

c++ - 修改引用变量,而不是它们别名的变量

c++ - 用整数值初始化非常量引用