Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.CodeDom.Compiler;
- using System.IO;
- using Microsoft.CSharp;
- namespace CodeDomTest
- {
- class Program
- {
- static void Main()
- {
- string source1 = File.ReadAllText(@"Source path here");
- string source2 = File.ReadAllText(@"Source path here");
- var results = CompileCsharpSource(new[] { source1, source2 }, "App.exe");
- if (results.Errors.Count == 0)
- Console.WriteLine("No Errors");
- else
- {
- foreach (CompilerError error in results.Errors)
- Console.WriteLine(error.ErrorText);
- }
- Console.ReadLine();
- }
- private static CompilerResults CompileCsharpSource(string[] sources, string output, params string[] references)
- {
- var parameters = new CompilerParameters(references, output);
- parameters.GenerateExecutable = true;
- using (var provider = new CSharpCodeProvider())
- return provider.CompileAssemblyFromSource(parameters, sources);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement