自己写了个编译c#的程序
这个是我写的一个编译c#程序的代码,现在困惑的是,这段代码编译的动态库是debug还是release呢?请朋友多多指点,谢谢,代码如下
public class CompileCSharpCode
{
/// <summary>
/// 编译文件
/// </summary>
/// <param name="SourceFile">文件物理路径</param>
/// <param name="DllFilePath">外部动态库位置</param>
/// <returns></returns>
public string CompileCode(string SourceFile, ArrayList DllFilePath)
{
CodeDomProvider compiler = new CSharpCodeProvider();
CompilerParameters Prams = new CompilerParameters();
Prams.ReferencedAssemblies.Add("mscorlib.dll");
Prams.ReferencedAssemblies.Add("System.dll");
Prams.ReferencedAssemblies.Add("System.Web.dll");
Prams.ReferencedAssemblies.Add("System.Data.dll");
Prams.ReferencedAssemblies.Add("System.Xml.dll");
Prams.IncludeDebugInformation = false;
string BaseDirectory = System.AppDomain.CurrentDomain.BaseDirectory; //应用程序执行目录
//读取basedll下所有动态库
string[] Files = Directory.GetFiles(BaseDirectory + "basedll", "*.dll", SearchOption.TopDirectoryOnly);
for (int i = 0; i < Files.Length; i++)
{
Prams.ReferencedAssemblies.Add(Files[i]);
}
//添加编译时引用的外部动态库
for (int i = 0; i < DllFilePath.Count; i++)
{
Prams.ReferencedAssemblies.Add(DllFilePath[i].ToString());
}
Prams.GenerateExecutable = false;
Prams.GenerateInMemory = false;
Prams.IncludeDebugInformation = false;
string DllFileName = Path.GetFileNameWithoutExtension(SourceFile)+".dll";
string[] TempSourceFile = new string[2];
//添加版本信息
TempSourceFile[0] = BaseDirectory + "VersionFile" + "\\AssemblyInfo.cs";
TempSourceFile[1] = SourceFile;
Prams.OutputAssembly = BaseDirectory + "exportdll\\" + DllFileName;
CompilerResults cr = compiler.CompileAssemblyFromFile(Prams, TempSourceFile);
if (cr.Errors.Count > 0)
{
string StrResult=string.Empty;
foreach(CompilerError ce in cr.Errors)
{
StrResult += ce.ToString()+"\n";
}
return StrResult;
}
else
{
return string.Empty;
}
}
}
{
/// <summary>
/// 编译文件
/// </summary>
/// <param name="SourceFile">文件物理路径</param>
/// <param name="DllFilePath">外部动态库位置</param>
/// <returns></returns>
public string CompileCode(string SourceFile, ArrayList DllFilePath)
{
CodeDomProvider compiler = new CSharpCodeProvider();
CompilerParameters Prams = new CompilerParameters();
Prams.ReferencedAssemblies.Add("mscorlib.dll");
Prams.ReferencedAssemblies.Add("System.dll");
Prams.ReferencedAssemblies.Add("System.Web.dll");
Prams.ReferencedAssemblies.Add("System.Data.dll");
Prams.ReferencedAssemblies.Add("System.Xml.dll");
Prams.IncludeDebugInformation = false;
string BaseDirectory = System.AppDomain.CurrentDomain.BaseDirectory; //应用程序执行目录
//读取basedll下所有动态库
string[] Files = Directory.GetFiles(BaseDirectory + "basedll", "*.dll", SearchOption.TopDirectoryOnly);
for (int i = 0; i < Files.Length; i++)
{
Prams.ReferencedAssemblies.Add(Files[i]);
}
//添加编译时引用的外部动态库
for (int i = 0; i < DllFilePath.Count; i++)
{
Prams.ReferencedAssemblies.Add(DllFilePath[i].ToString());
}
Prams.GenerateExecutable = false;
Prams.GenerateInMemory = false;
Prams.IncludeDebugInformation = false;
string DllFileName = Path.GetFileNameWithoutExtension(SourceFile)+".dll";
string[] TempSourceFile = new string[2];
//添加版本信息
TempSourceFile[0] = BaseDirectory + "VersionFile" + "\\AssemblyInfo.cs";
TempSourceFile[1] = SourceFile;
Prams.OutputAssembly = BaseDirectory + "exportdll\\" + DllFileName;
CompilerResults cr = compiler.CompileAssemblyFromFile(Prams, TempSourceFile);
if (cr.Errors.Count > 0)
{
string StrResult=string.Empty;
foreach(CompilerError ce in cr.Errors)
{
StrResult += ce.ToString()+"\n";
}
return StrResult;
}
else
{
return string.Empty;
}
}
}

浙公网安备 33010602011771号