我正在使用 CSharpCodeProvider 在运行时编译一个 DLL。我的代码在某些机器上运行良好,但在其他机器上失败并出现以下错误:
错误 CS0006:找不到元数据文件“EntityFramework.dll”
这是一个代码片段:
var csFile = ... // the file is in C:\Program Data\MyFolder\InnerFolder
using (var provider = new CSharpCodeProvider())
{
var parameters = new CompilerParameters
{
GenerateInMemory = false, // we want the dll saved to disk
GenerateExecutable = false,
CompilerOptions = "/target:library",
// the assembly is compiled to the same directory as the .cs file
OutputAssembly = GetNewCacheAssemblyPath(),
};
parameters.ReferencedAssemblies.AddRange(new[]
{
"System.dll",
"System.Data.dll",
"System.Data.Entity.dll",
"EntityFramework.dll",
});
var compilerResult = provider.CompileAssemblyFromFile(parameters, csFile);
}
关于为什么会发生这种情况的任何想法?