C# 编译器错误 CS0006: 未找到元数据文件

发布于 12-18 05:26 字数 1861 浏览 5 评论 0原文

我已经使用 MSDN 上的教程和其他一些资源(包括此处)构建了 ac# 编译器,并且在添加其他参考程序集之前我已经让它可以工作了。我的错误源于将“System.dll”和“System.Windows.Forms.dll”添加到 ReferenceAssemblies 列表中。

这是我的代码:

private void SetUpCompilingParameters()
    {
        string ver = string.Format("{0}.{1}.{2}", Environment.Version.Major, Environment.Version.MajorRevision, Environment.Version.Build);
        string libDir = string.Format(@"{0}", Environment.CurrentDirectory);
        string raDir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0";
        string exWpfDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}\WPF", ver);
        string exDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}", ver);            

        MyCompiler = new CSharpCodeProvider();
        CompilingParam = new CompilerParameters();
        CompilingParam.GenerateExecutable = false;
        CompilingParam.GenerateInMemory = true;
        CompilingParam.IncludeDebugInformation = false;
        CompilingParam.TreatWarningsAsErrors = false;
        CompilingParam.CompilerOptions = string.Format("/lib:{0}", libDir);
        CompilingParam.CompilerOptions = string.Format("/lib:{0}", raDir);
        CompilingParam.CompilerOptions = string.Format("/lib:{0}", exDir);
        //CompilingParam.CompilerOptions = string.Format("/lib:{0}", exWpfDir);

        CompilingParam.ReferencedAssemblies.Add("System.dll");
        CompilingParam.ReferencedAssemblies.Add("System.Windows.Forms.dll");

    }

如您所见,我已在 CompilerOptions 中明确引用了目录,但它没有帮助。我想在stackoverflow上测试该解决方案 使用:

CompilingParam.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location);

但我在将它用于一般 System.dll 等时遇到问题...

I've built a c# compiler using the tutorial on MSDN and a few other resources including here, and I've gotten it to work until I add additional reference assemblies. My errors stem from adding "System.dll" and "System.Windows.Forms.dll" to the ReferenceAssemblies list.

here's my code:

private void SetUpCompilingParameters()
    {
        string ver = string.Format("{0}.{1}.{2}", Environment.Version.Major, Environment.Version.MajorRevision, Environment.Version.Build);
        string libDir = string.Format(@"{0}", Environment.CurrentDirectory);
        string raDir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0";
        string exWpfDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}\WPF", ver);
        string exDir = string.Format(@"C:\WINDOWS\Microsoft.NET\Framework\v{0}", ver);            

        MyCompiler = new CSharpCodeProvider();
        CompilingParam = new CompilerParameters();
        CompilingParam.GenerateExecutable = false;
        CompilingParam.GenerateInMemory = true;
        CompilingParam.IncludeDebugInformation = false;
        CompilingParam.TreatWarningsAsErrors = false;
        CompilingParam.CompilerOptions = string.Format("/lib:{0}", libDir);
        CompilingParam.CompilerOptions = string.Format("/lib:{0}", raDir);
        CompilingParam.CompilerOptions = string.Format("/lib:{0}", exDir);
        //CompilingParam.CompilerOptions = string.Format("/lib:{0}", exWpfDir);

        CompilingParam.ReferencedAssemblies.Add("System.dll");
        CompilingParam.ReferencedAssemblies.Add("System.Windows.Forms.dll");

    }

As you can see, I've explicitly referenced directories in CompilerOptions but its not helping. I'd like to test the solution on here on stackoverflow
that utilizes:

CompilingParam.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location);

but I'm having trouble using it for the general System.dll etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文