public static bool ExtractPackage(DTE dte, string toolPath, UnpackSettings unpackSettings, string commandArgs) { var command = new SolutionPackagerCommand { Action = SolutionPackagerAction.Extract.ToString(), CommandArgs = commandArgs, ToolPath = toolPath, SolutionName = unpackSettings.CrmSolution.Name }; ExecuteSolutionPackager(command); var solutionFileDelete = RemoveDeletedItems(unpackSettings.ExtractedFolder.FullName, unpackSettings.Project.ProjectItems, unpackSettings.SolutionPackageConfig.packagepath); var solutionFileAddChange = ProcessDownloadedSolution(unpackSettings.ExtractedFolder, unpackSettings.ProjectPackageFolder, unpackSettings.Project.ProjectItems); FileSystem.DeleteDirectory(unpackSettings.ExtractedFolder.FullName); if (!unpackSettings.SaveSolutions) { return(true); } //Solution change or file not present var solutionChange = solutionFileDelete || solutionFileAddChange; var solutionStored = StoreSolutionFile(unpackSettings, solutionChange); return(solutionStored); }
private static ProcessStartInfo CreateProcessStartInfo(SolutionPackagerCommand command) { var processStartInfo = new ProcessStartInfo { FileName = "cmd", Arguments = $"/c \"{command.ToolPath} {command.CommandArgs}\"", RedirectStandardError = true, RedirectStandardOutput = true, CreateNoWindow = true, UseShellExecute = false }; return(processStartInfo); }
public static bool CreatePackage(string toolPath, PackSettings packSettings, string commandArgs) { var command = new SolutionPackagerCommand { Action = SolutionPackagerAction.Pack.ToString(), CommandArgs = commandArgs, ToolPath = toolPath, SolutionName = packSettings.CrmSolution.Name }; ExecuteSolutionPackager(command); if (!packSettings.SaveSolutions) { return(true); } packSettings.Project.ProjectItems.AddFromFile(packSettings.FullFilePath); return(true); }
public static bool ExecuteSolutionPackager(SolutionPackagerCommand command) { OutputLogger.WriteToOutputWindow($"{Resource.Message_Begin} {command.Action}: {command.SolutionName}", MessageType.Info); const int timeout = 60000; var workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (string.IsNullOrEmpty(workingDirectory)) { OutputLogger.WriteToOutputWindow(Resource.ErrorMessage_CouldNotSetWorkingDirectory, MessageType.Error); return(false); } using (var process = new System.Diagnostics.Process()) { var processStartInfo = CreateProcessStartInfo(command); process.StartInfo = processStartInfo; process.StartInfo.WorkingDirectory = workingDirectory; var output = new StringBuilder(); var errorDataReceived = new StringBuilder(); using (var outputWaitHandle = new AutoResetEvent(false)) { using (var errorWaitHandle = new AutoResetEvent(false)) { process.OutputDataReceived += (sender, e) => { if (e.Data == null) { outputWaitHandle.Set(); } else { output.AppendLine(e.Data); } }; process.ErrorDataReceived += (sender, e) => { if (e.Data == null) { errorWaitHandle.Set(); } else { errorDataReceived.AppendLine(e.Data); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); string message; if (process.WaitForExit(timeout) && outputWaitHandle.WaitOne(timeout) && errorWaitHandle.WaitOne(timeout)) { if (process.ExitCode == 0) { OutputLogger.WriteToOutputWindow($"{Resource.Message_End} {command.Action}: {command.SolutionName}", MessageType.Info); return(true); } message = $"{Resource.Message_ErrorExecutingSolutionPackager}: {command.Action}: {command.SolutionName}"; } else { message = $"{Resource.Message_TimoutExecutingSolutionPackager}: {command.Action}: {command.SolutionName}"; } ExceptionHandler.LogProcessError(Logger, message, errorDataReceived.ToString()); MessageBox.Show(message); } } } return(false); }