本文整理汇总了C#中Microsoft.CSharp.CSharpCodeProvider.Supports方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpCodeProvider.Supports方法的具体用法?C# CSharpCodeProvider.Supports怎么用?C# CSharpCodeProvider.Supports使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CSharp.CSharpCodeProvider
的用法示例。
在下文中一共展示了CSharpCodeProvider.Supports方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileCode
private static bool CompileCode(List<string> sourceFile, String exeFile, string[] libraries)
{
CodeDomProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
List<string> codeLines = new List<string>();
cp.GenerateExecutable = true;
cp.OutputAssembly = exeFile;
cp.IncludeDebugInformation = false;
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.core.dll");
cp.GenerateInMemory = false;
cp.WarningLevel = 1;
cp.TreatWarningsAsErrors = false;
cp.CompilerOptions = "/optimize";
cp.TempFiles = new TempFileCollection(".", false);
if (provider.Supports(GeneratorSupport.EntryPointMethod))
{
cp.MainClass = "ProblemNamespace.ProblemClass";
}
if (libraries != null)
codeLines.AddRange(libraries.Select(l => "using " + l + ";"));
codeLines.AddRange(new[]
{
"using System;\n",
"namespace ProblemNamespace\n",
"{\n",
"class ProblemClass\n",
"{\n",
"static void Main(string[] args)\n",
"{\n"
});
codeLines.AddRange(sourceFile);
codeLines.AddRange(new[]
{
//"Console.ReadKey();\n",
"}\n",
"}\n",
"}\n"
});
string finalCode = String.Join("", codeLines);
CompilerResults cr = provider.CompileAssemblyFromSource(cp, finalCode);
if (cr.Errors.Count > 0)
{
Console.WriteLine("Errors building {0} into {1}",
sourceFile, cr.PathToAssembly);
foreach (CompilerError ce in cr.Errors)
{
Console.WriteLine(" {0}", ce.ToString());
Console.WriteLine();
}
}
else
{
Console.WriteLine("Source {0} built into {1} successfully.",
sourceFile, cr.PathToAssembly);
Console.WriteLine("{0} temporary files created during the compilation.",
cp.TempFiles.Count);
}
return cr.Errors.Count <= 0;
}