我在运行时使用CSharpCodeProvider编译DLL。我的代码运行在某些机器上正常,但在otherse失败,出现以下错误:CSharpProvider运行时编译无法找到DLL
error CS0006: Metadata file 'EntityFramework.dll' could not be found
下面的代码片段:
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);
}
任何想法,为什么这可能发生?
做的所有机器都安装了Entity框架吗?如果没有,你可能需要在其上安装.Net framework 4或手动部署它 – Amitd
@Amitd:什么是最简单的方法来确定是否是这种情况?据我所知,所有这些机器都安装了.NET 4。这些是开发者机器,我们的应用程序(它使用EF正在开发中......) – ChaseMedallion
for EF更多信息在这个页面上http://stackoverflow.com/questions/6498388/could-not-locate-assembly-entityframework。 。可能是有版本差异..没有线索..也尝试复制输出文件夹中的dll像汉斯说 – Amitd