最近研究CodeDomProvider,但是编译linq时总是报错,编译决是不过,后来在国外的网站找到了原来CodeDomProvider是有版本的,代码如下:
// 创建编译器对象
CodeDomProvider p = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });//CodeDomProvider.CreateProvider("CSharp");
//ICodeCompiler cc = p.CreateCompiler();
// 设置编译参数
CompilerParameters options = new CompilerParameters();
options.IncludeDebugInformation = true;
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll");
options.ReferencedAssemblies.Add("System.Data.dll");
options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll");
options.ReferencedAssemblies.Add("System.Deployment.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll");
options.ReferencedAssemblies.Add("System.Drawing.dll");
options.ReferencedAssemblies.Add("System.Windows.Forms.dll");
options.GenerateInMemory = true;
options.OutputAssembly = "MyTest";
// 开始编译
//CodeSnippetCompileUnit cu = new CodeSnippetCompileUnit(code);
CompilerResults cr = p.CompileAssemblyFromFile(options, code);
CodeDomProvider p = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });//CodeDomProvider.CreateProvider("CSharp");
//ICodeCompiler cc = p.CreateCompiler();
// 设置编译参数
CompilerParameters options = new CompilerParameters();
options.IncludeDebugInformation = true;
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll");
options.ReferencedAssemblies.Add("System.Data.dll");
options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll");
options.ReferencedAssemblies.Add("System.Deployment.dll");
options.ReferencedAssemblies.Add("System.Xml.dll");
options.ReferencedAssemblies.Add(@"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll");
options.ReferencedAssemblies.Add("System.Drawing.dll");
options.ReferencedAssemblies.Add("System.Windows.Forms.dll");
options.GenerateInMemory = true;
options.OutputAssembly = "MyTest";
// 开始编译
//CodeSnippetCompileUnit cu = new CodeSnippetCompileUnit(code);
CompilerResults cr = p.CompileAssemblyFromFile(options, code);