diff --git a/tools/xibuild/Main.cs b/tools/xibuild/Main.cs index 3c9ad4cb496e..f4a0337b231a 100644 --- a/tools/xibuild/Main.cs +++ b/tools/xibuild/Main.cs @@ -115,23 +115,29 @@ static int RunTool (string toolPath, string combinedArgs, string baseConfigFile) { var tmpMSBuildExePathForConfig = Path.GetTempFileName (); var configFilePath = tmpMSBuildExePathForConfig + ".config"; - - GenerateAppConfig (configFilePath, baseConfigFile, out string MSBuildSdksPath); - - var psi = new ProcessStartInfo { - FileName = toolPath, - Arguments = combinedArgs, - UseShellExecute = false, - }; - // Required so that msbuild can read the correct config file - psi.EnvironmentVariables ["MSBUILD_EXE_PATH"] = tmpMSBuildExePathForConfig; - // MSBuildSDKsPath only works via an env var - psi.EnvironmentVariables ["MSBuildSDKsPath"] = MSBuildSdksPath; - - var p = Process.Start (psi); - - p.WaitForExit (); - return p.ExitCode; + try { + GenerateAppConfig (configFilePath, baseConfigFile, out string MSBuildSdksPath); + + var psi = new ProcessStartInfo { + FileName = toolPath, + Arguments = combinedArgs, + UseShellExecute = false, + }; + // Required so that msbuild can read the correct config file + psi.EnvironmentVariables ["MSBUILD_EXE_PATH"] = tmpMSBuildExePathForConfig; + // MSBuildSDKsPath only works via an env var + psi.EnvironmentVariables ["MSBuildSDKsPath"] = MSBuildSdksPath; + + var p = Process.Start (psi); + + p.WaitForExit (); + return p.ExitCode; + } finally { + if (File.Exists (tmpMSBuildExePathForConfig)) + File.Delete (tmpMSBuildExePathForConfig); + if (File.Exists (tmpMSBuildExePathForConfig)) + File.Delete (configFilePath); + } } static void GenerateAppConfig (string targetConfigFile, string baseConfigFile, out string MSBuildSdksPath)