From d46eb9e638e3ee55f4bc07b5416e499458106579 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 24 Oct 2017 13:04:41 -0500 Subject: [PATCH] [xabuild] print config file to console on error There are cases in which diagnostic MSBuild output is not including important information such as `$(MSBuildExtensionsPath)`. To help debug situations like this, if `MSBuildApp.Main` returns a non-zero exit code, we can print the contents of xabuild.exe's config file to the console. --- tools/xabuild/XABuild.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/xabuild/XABuild.cs b/tools/xabuild/XABuild.cs index 0b95dd6c3c7..7f30cff3f8e 100644 --- a/tools/xabuild/XABuild.cs +++ b/tools/xabuild/XABuild.cs @@ -18,7 +18,7 @@ static int Main () } //Create a custom xabuild.exe.config - CreateConfig (paths); + var xml = CreateConfig (paths); //Create link to .NETFramework and .NETPortable directory foreach (var dir in Directory.GetDirectories (paths.SystemProfiles)) { @@ -28,7 +28,19 @@ static int Main () } } - return MSBuildApp.Main (); + int exitCode = MSBuildApp.Main (); + if (exitCode != 0) { + Console.WriteLine ($"MSBuildApp.Main exited with {exitCode}, xabuild configuration is:"); + + var settings = new XmlWriterSettings { + Indent = true, + NewLineOnAttributes = true, + }; + using (var writer = XmlTextWriter.Create (Console.Out, settings)) { + xml.WriteTo (writer); + } + } + return exitCode; } finally { //NOTE: these are temporary files foreach (var file in new [] { paths.MSBuildExeTempPath, paths.XABuildConfig }) { @@ -39,7 +51,7 @@ static int Main () } } - static void CreateConfig (XABuildPaths paths) + static XmlDocument CreateConfig (XABuildPaths paths) { var xml = new XmlDocument (); xml.Load (paths.MSBuildConfig); @@ -90,6 +102,7 @@ static void CreateConfig (XABuildPaths paths) xml.Save (paths.XABuildConfig); Environment.SetEnvironmentVariable ("MSBUILD_EXE_PATH", paths.MSBuildExeTempPath, EnvironmentVariableTarget.Process); + return xml; } ///