【发布时间】:2011-12-15 13:20:51
【问题描述】:
我在一个 XML 文件中有一些代码,我在应用程序运行时加载和编译这些代码。
这在 Windows 上运行良好,但在 Mono 下我得到程序集引用错误。这是有问题的检查代码:
public static bool CompileSpell(Spell spell)
{
CSharpCodeProvider prov = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = true;
cp.GenerateInMemory = true;
cp.ReferencedAssemblies.Add("system.dll");
cp.ReferencedAssemblies.Add("system.xml.dll");
cp.ReferencedAssemblies.Add("BasternaeMud.dll");
cp.ReferencedAssemblies.Add("ZoneData.dll");
Log.Trace("Compiling spell '" + spell.Name + "'.");
StringBuilder sb = new StringBuilder();
int idx = spell.FileName.IndexOf('.');
string file = spell.FileName;
if (idx > 0)
{
file = spell.FileName.Substring(0, idx);
}
int lines = GenerateWithMain(sb, spell.Code, "BasternaeMud");
CompilerResults cr = prov.CompileAssemblyFromSource(cp,sb.ToString());
....
我在编译结果中得到的具体错误是:
cannot find metadata file 'system.dll' at line 0 column 0.
cannot find metadata file 'system.xml.dll' at line 0 column 0.
Mono 显然不喜欢我在为 system.xml 和 system.xml.dll 编译的代码中添加引用程序集的方式。其他两个程序集添加得很好,这并不奇怪,因为它们是编译器实际执行的代码,并且存在于可执行目录中。
任何线索我需要做些什么来解决这个问题?
也许我可以将那些 DLL 放到可执行目录中,但这感觉是个愚蠢的想法。
【问题讨论】: