I have a project in c# that I would like to compile programmatically and put it in Release folder.
I am using CodeDomProvider, here below is my code:
class Compiler
{
public static void Build(string filename,string outputAssemblyPath)
{
CodeDomProvider cdp = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters cp = new CompilerParameters()
{
GenerateExecutable = true,
GenerateInMemory = true,
IncludeDebugInformation = true,
OutputAssembly = outputAssemblyPath
};
CompilerResults result = cdp.CompileAssemblyFromFile(cp, filename);
foreach (string s in result.Output)
{
Console.WriteLine(s);
}
}
}
I am calling Build method the following way:
class Program
{
static void Main(string[] args)
{
Compiler.Build("C:/Projects/Project1/alan.project/Project1.csproj", "C:/Projects/Project1/alan.project/bin/Release/");
Console.ReadLine();
}
}
All I want to do is instead of clicking "Rebuild" and have my project compiled in the Release directory, I want it done programmatically.
OutputAssembly-property on theCompilerParameter-argument provided to theCompileFrom...-method.CompilerOptionswith/outargument?/out:D:\\Alan\\AssemblyName