I'm trying to dynamically compile s开发者_运维问答ource code using the CodeDom.Compiler stuff, which means I need to reference the basic assemblies manually. The source code that I am compiling must be able to access the basic list extension methods, for for instance, Max(), Min(), or Sum(), and probably lambda expressions as well.
When I compile the source, it says I'm missing the required assembly... currently I include System.dll, and System.Core.dll.
Which dll do I need to get the extension methods for generics?
Have a look at this blog post. You have to specify the compiler version manually when calling the CSharpCodeProvider
constructor that receives a dictionary. Like this:
var provider = new CSharpCodeProvider(new Dictionary<string, string>{
{"CompilerVersion", "v3.5"} });
The simple way to get past these type of hassles, is to look through Assembly.GetReferencedAssemblies(), and add references to the compiler that way. Then you know as long as your compiler compiles in Visual Studio, any code using those features will compile with your compiler.
精彩评论