private string GetSliceCompilerPath(Microsoft.Build.Evaluation.Project project, string iceHome) { ThreadHelper.ThrowIfNotOnUIThread(); string compiler = MSBuildUtils.IsCSharpProject(project) ? "slice2cs.exe" : "slice2cpp.exe"; if (!string.IsNullOrEmpty(iceHome)) { if (File.Exists(Path.Combine(iceHome, "cpp", "bin", compiler))) { return(Path.Combine(iceHome, "cpp", "bin", compiler)); } if (File.Exists(Path.Combine(iceHome, "bin", compiler))) { return(Path.Combine(iceHome, "bin", compiler)); } } string message = "'" + compiler + "' not found"; if (!string.IsNullOrEmpty(iceHome)) { message += " in '" + iceHome + "'. You may need to update Ice Home in 'Tools > Options > Ice'"; } else { message += ". You may need to set Ice Home in 'Tools > Options > Ice'"; } OutputPane.OutputTaskItemString( message, EnvDTE.vsTaskPriority.vsTaskPriorityHigh, "BuildCompile", EnvDTE.vsTaskIcon.vsTaskIconCompile, compiler, 0, message); return(null); }
// // With Ice >= 3.7.0 we get the compiler version from Ice.props // private string GetSliceCompilerVersion(string iceHome) { string sliceCompiler = GetSliceCompilerPath(null, iceHome); if (!File.Exists(sliceCompiler)) { string message = string.Format("'{0}' not found, review your Ice installation", sliceCompiler); OutputPane.OutputTaskItemString( message, EnvDTE.vsTaskPriority.vsTaskPriorityHigh, EnvDTE.vsTaskCategories.vsTaskCategoryBuildCompile, EnvDTE.vsTaskIcon.vsTaskIconCompile, sliceCompiler, 0, message); return(null); } Process process = new Process(); process.StartInfo.FileName = sliceCompiler; process.StartInfo.Arguments = "-v"; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(sliceCompiler); StreamReader reader = new StreamReader(); process.OutputDataReceived += new DataReceivedEventHandler(reader.appendData); try { process.Start(); // // When StandardError and StandardOutput are redirected, at least one // should use asynchronous reads to prevent deadlocks when calling // process.WaitForExit; the other can be read synchronously using ReadToEnd. // // See the Remarks section in the below link: // // http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standarderror.aspx // // Start the asynchronous read of the standard output stream. process.BeginOutputReadLine(); // Read Standard error. string version = process.StandardError.ReadToEnd().Trim(); process.WaitForExit(); if (process.ExitCode != 0) { string message = string.Format("Slice compiler `{0}' failed to start(error code {1})", sliceCompiler, process.ExitCode); OutputPane.OutputTaskItemString( message, EnvDTE.vsTaskPriority.vsTaskPriorityHigh, EnvDTE.vsTaskCategories.vsTaskCategoryBuildCompile, EnvDTE.vsTaskIcon.vsTaskIconCompile, sliceCompiler, 0, message); return(null); } // // Convert beta version to is numeric value // if (version.EndsWith("b")) { version = string.Format("{0}.{1}", version.Substring(0, version.Length - 1), 51); } return(version); } catch (Exception ex) { string message = string.Format("An exception was thrown when trying to start the Slice compiler\n{0}", ex.ToString()); OutputPane.OutputTaskItemString( message, EnvDTE.vsTaskPriority.vsTaskPriorityHigh, EnvDTE.vsTaskCategories.vsTaskCategoryBuildCompile, EnvDTE.vsTaskIcon.vsTaskIconCompile, sliceCompiler, 0, message); return(null); } finally { process.Close(); } }