C# 编译器错误 CS0006: 未找到元数据文件
我已经使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论