i want to compile a .cs program which exist in some other folder on the disk and generate a .dll of it, using another .cs program or a console application or a window application. i tried using the following
using (StreamReader textReader = new StreamReader(@"path\Filename.cs"))
{
textFile = textReader.ReadToEnd();
Console.WriteLine(textFile);
}
CodeDomProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler compiler = codeProvider.CreateCompiler();
// add compiler parameters
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.CompilerOptions = "/target:library /optimize";
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
// compile the code
CompilerResults results = compiler.CompileAssemblyFromSource(compilerParams, textFile);
I have idea something like this till you don’t find something concrete try this
You can call this from on cs file to compile other cs file. Check if it works …. \
By default process will search the files in system32 dir so use the following code to do that…
In argument i have given path of cs file as C:\ss\Class1.cs you give according to your path but keep in mind give small path.