/// <summary> /// Compiles C# code in run time. /// </summary> private static bool CompileDynamic( string codeData, string outputFilePathName, string dotNetVersion) { string systemRoot = Environment.GetEnvironmentVariable("SystemRoot"); string cscExePathName = string.Format( @"{0}\Microsoft.NET\Framework\{1}\csc.exe", systemRoot, dotNetVersion); string tempCsFilePathName = Path.Combine(s_basePath, "code.cs"); File.WriteAllText( tempCsFilePathName, codeData); Process p = ServiceHelper_Accessor.CreateCustomProcess( cscExePathName, string.Format( "/optimize \"/out:{0}\" \"{1}\"", outputFilePathName, tempCsFilePathName)); p.Start(); p.StandardOutput.ReadToEnd(); File.Delete(tempCsFilePathName); return(p.ExitCode == 0); }
public void Custom_Process_Creation() { Process p = ServiceHelper_Accessor.CreateCustomProcess( "cmd.exe", null); p.Start(); p.StandardInput.WriteLine("exit"); string output = p.StandardOutput.ReadToEnd(); Assert.AreEqual(0, p.ExitCode); Assert.IsTrue(output.StartsWith("Microsoft Windows")); }