
Compile CS source code using ICodeCompiler
Hi,
I want to compile CS source code in program. However, I always get error
"CS0116 - A namespace does not directly contain members such as fields or
methods" when I invoke CompileAssemblyFromSource method. Even if I changed
the source file name to an invalid value, the same error message will be
returned. How does this happen?
This is my code:
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
cp.ReferencedAssemblies.Add("System.Web.Services.dll");
cp.GenerateExecutable = false;
cp.OutputAssembly = "C:\\Lib\\BT20TT0.dll;
cp.GenerateInMemory = true;
cp.IncludeDebugInformation = false;
CSharpCodeProvider cscp = new CSharpCodeProvider();
ICodeCompiler icc = cscp.CreateCompiler();
CompilerResults cr = icc.CompileAssemblyFromSource(cp,
"C:\\Source\\BT20TT0.cs");
Thanks & Regards,
Weiming