diff --git a/Framework.VSIX/FrameworkProjectWizard.cs b/Framework.VSIX/FrameworkProjectWizard.cs index 0cbd356..b0eea15 100644 --- a/Framework.VSIX/FrameworkProjectWizard.cs +++ b/Framework.VSIX/FrameworkProjectWizard.cs @@ -9,6 +9,7 @@ using System.Resources; using Framework.VSIX.Resources; using System.Reflection; +using System.Threading.Tasks; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Extensibility; using Microsoft.ApplicationInsights.DataContracts; @@ -56,40 +57,47 @@ public void ProjectFinishedGenerating(Project project) proc.StartInfo.WorkingDirectory = genDir; proc.StartInfo.FileName = @"cmd.exe"; + Task outTask = null; + Task errTask = null; + if (showWindow == false) { - proc.StartInfo.Arguments = string.Format(@" /c {0}", commandString); - proc.StartInfo.RedirectStandardInput = true; - proc.StartInfo.RedirectStandardOutput = true; - proc.StartInfo.RedirectStandardError = true; - proc.StartInfo.CreateNoWindow = true; - proc.StartInfo.UseShellExecute = false; - proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - proc.Start(); - - proc.StandardInput.Flush(); - proc.StandardInput.WriteLine("exit"); - proc.StandardInput.Flush(); - - using (StreamReader reader = proc.StandardOutput) - { - string result = reader.ReadToEnd(); - outputText.Append(result); - } - - using (StreamReader reader = proc.StandardError) - { - string result = reader.ReadToEnd(); - outputText.Append(result); - } + try + { + proc.StartInfo.Arguments = string.Format(@" /c {0}", commandString); + proc.StartInfo.RedirectStandardInput = true; + proc.StartInfo.RedirectStandardOutput = true; + proc.StartInfo.RedirectStandardError = true; + proc.StartInfo.CreateNoWindow = true; + proc.StartInfo.UseShellExecute = false; + proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + proc.Start(); + + proc.StandardInput.Flush(); + proc.StandardInput.WriteLine("exit"); + proc.StandardInput.Flush(); + + outTask = Task.Run(() => proc.StandardOutput.ReadToEndAsync()); + errTask = Task.Run(() => proc.StandardError.ReadToEndAsync()); + } + catch (System.Exception ex) + { + //TODO: Log Error + } } else { proc.StartInfo.Arguments = string.Format(@" /k {0}", commandString); proc.Start(); } + + proc.WaitForExit(); - proc.WaitForExit(); + if (showWindow == false) + { + outputText.Append(outTask.Result); + outputText.Append(errTask.Result); + } using (StreamWriter sw = File.AppendText(logFile)) { @@ -97,10 +105,17 @@ public void ProjectFinishedGenerating(Project project) } } - telemetry.TrackEvent("project-wizard", telProps, null); - // Allow some time for flushing before shutdown. - telemetry.Flush(); - System.Threading.Thread.Sleep(1000); + try + { + telemetry.TrackEvent("project-wizard", telProps, null); + // Allow some time for flushing before shutdown. + telemetry.Flush(); + System.Threading.Thread.Sleep(1000); + } + catch (System.Exception ex) + { + //TODO: Log error + } string[] files = Directory.GetFiles(projectDir, "*.*", SearchOption.AllDirectories); diff --git a/Framework.VSIX/source.extension.vsixmanifest b/Framework.VSIX/source.extension.vsixmanifest index 5364b99..ddd3eb3 100644 --- a/Framework.VSIX/source.extension.vsixmanifest +++ b/Framework.VSIX/source.extension.vsixmanifest @@ -1,7 +1,7 @@ - + SPFx Project Template New SharePoint Framework Project. https://github.com/SharePoint/sp-dev-fx-vs-extension