how to programatically create a class library using C# compiler

Jan 23 2009 9:58 AM
hi,
i want to develop a window application that will get a '.cs file' as input from a text box and create a class library(.dll file) for it.

this is the method i used to programmatically compile code and generate the executable, but i want to generate a dll.

private void Compile()
{

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
string Output = "testAssembly.exe";
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
CompilerResults results = icc.CompileAssemblyFromSource(parameters, txtOutput.Text.ToString());

//txtOutput is the text box where i give my code
if (results.Errors.Count > 0)
{
foreach (CompilerError CompErr in results.Errors)
{
MessageBox.Show( "Line number " + CompErr.Line +
", Error Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + ";" +
Environment.NewLine + Environment.NewLine);
}

}
else
{
MessageBox.Show("Success");
}
}

this is the link i referred for programmatically compiling code using C# compiler that creates exe.
http://support.microsoft.com/kb/304655


help plz,

thanx in advance.

Answers (2)