CompilerParameters.ReferencedAssemblies -- 添加对 System.Web.UI.WebControls 的引用 [英] CompilerParameters.ReferencedAssemblies -- Add reference to System.Web.UI.WebControls

查看:29
本文介绍了CompilerParameters.ReferencedAssemblies -- 添加对 System.Web.UI.WebControls 的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CodeDomProvider 类在运行时编译类.这适用于仅使用 System 命名空间的类:

I am compiling classes at run-time using the CodeDomProvider class. This works fine for classes only using the System namespace:

using System;

public class Test
{
    public String HelloWorld()
    {
        return "Hello World!";
    }
}

如果我尝试使用 System.Web.UI.WebControls 编译一个类,我会收到此错误:

If I try to compile a class using System.Web.UI.WebControls though, I get this error:

{错误 CS0006:找不到元数据文件System.Web.UI.WebControls"}System.CodeDom.Compiler.CompilerError

{error CS0006: Metadata file 'System.Web.UI.WebControls' could not be found} System.CodeDom.Compiler.CompilerError

这是我的代码片段:

var cp = new CompilerParameters();

cp.ReferencedAssemblies.Add("System.Web.UI.WebControls");

如何引用 System.Web.UI.WebControls 命名空间?

How do I reference the System.Web.UI.WebControls namespace?

推荐答案

您引用程序集,而不是命名空间.您应该使用 MSDN 来查找包含您需要使用的类的程序集的名称:在这种情况下,它将是:

You reference assemblies, not namespaces. You should use MSDN to look up the name of the assembly that contains the classes you need to use: in this case it's going to be:

var cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Web.dll");

这篇关于CompilerParameters.ReferencedAssemblies -- 添加对 System.Web.UI.WebControls 的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆