From 4586171c4cf9832214d2a9712280c8753bda8ab2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 3 Dec 2019 14:42:56 +0100 Subject: [PATCH] [xibuild] Clean up temporary files when done. (#7508) --- tools/xibuild/Main.cs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) 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)