/// <summary> /// Runs the compiled application as a separate process. /// </summary> public void RunCompiledApp() { String execName = _assemblyName + ".exe"; String execPath = DirectorySW.GetCurrentDirectory() + "\\bin\\Release\\" + execName; GlobalLog.LogStatus("Running Avalon app..."); TimeSpan timeOutSpan = new TimeSpan(0, 0, 180); ProcessSW p = new ProcessSW(); ProcessStartInfoSW info = new ProcessStartInfoSW(); info.FileName = execPath; p.StartInfo = info; p.Start(); bool exited = p.WaitForExit((int)timeOutSpan.TotalMilliseconds); if (!exited) { while (!p.HasExited) { p.Kill(); } } // If an exception happened within the Avalon app, // forward that exception now. Exception testResultEx = SerializationHelper.RetrieveException(); if (testResultEx != null) { SerializationHelper.StoreException(null); throw new TestValidationException("Exception was logged while running compiled app.\r\n\r\n" + testResultEx, testResultEx); } GlobalLog.LogStatus("Avalon app compiled and ran without error."); }
/// <summary> /// Deletes old app definition files, project files, and built components /// left over from previous runs. /// /// When we run in an automated test run, the previous test process may not have /// died completely, and it may still hold access /// to the files/directories we are trying to delete. Thus, we make multiple /// attempts to cleanup, sleeping for some time between attempts. /// </summary> public void CleanUpCompilation() { GlobalLog.LogStatus("Cleaning up compilation directory, if there is any...."); // Initialization for the multi-attempt logic bool cleanupDone = false; int maxAttempts = 5; int timeBetweenAttempts = 1000; // sleep time, in milliseconds int attempt = 0; while (!cleanupDone && attempt < maxAttempts) { attempt++; try { // Delete appdef file. if (FileSW.Exists(_appDefFileName)) { GlobalLog.LogStatus("Found appdef file " + _appDefFileName + ". Deleting..."); FileSW.Delete(_appDefFileName); } string currentFolder = DirectorySW.GetCurrentDirectory(); // Delete bin directory. string binPath = PathSW.Combine(currentFolder, "bin"); if (DirectorySW.Exists(binPath)) { GlobalLog.LogStatus("Found bin folder " + binPath + ". Deleting..."); DirectorySW.Delete(binPath, true); GlobalLog.LogStatus("Bin folder deleted."); } // Delete obj directory. string objPath = PathSW.Combine(currentFolder, "obj"); if (DirectorySW.Exists(objPath)) { GlobalLog.LogStatus("Found obj folder " + objPath + ". Deleting..."); DirectorySW.Delete(objPath, true); GlobalLog.LogStatus("Obj folder deleted."); } // Cleanup done! cleanupDone = true; } catch (Exception e) { // We catch only IOException or UnauthorizedAccessException // since those are thrown if some other process is using the // files and directories we are trying to delete. if (e is IOException || e is UnauthorizedAccessException) { GlobalLog.LogStatus("Cleanup attempt #" + attempt + " failed."); if ((1 == attempt) || (maxAttempts == attempt)) { GlobalLog.LogStatus("Here are the active processes on the system."); LogProcessesInfo(); } if (maxAttempts == attempt) { GlobalLog.LogStatus("Maximum no. of cleanup attempts reached. Bailing out...."); throw; } } else { throw; } } Thread.Sleep(timeBetweenAttempts); } }
private List <ErrorWarningCode> CompileInternal(bool saveProjFile) { if (FileSW.Exists("ClickOnceTest.pfx")) { MSBuildProjExecutor.CleanSignFile = false; } MSBuildProjExecutor build = new MSBuildProjExecutor(); build.CreateProject(); build.CreateBuildPropertyGroup(""); build.CreateBuildItemGroup(""); build.AddProperty("Configuration", SetupParams.Configuration); build.AddProperty("Platform", "AnyCPU"); build.AddProperty("XamlDebuggingInformation", Convert.ToString(SetupParams.XamlDebuggingInformation)); build.AddProperty("OutputType", SetupParams.OutputType); if (!IsLibrary() && SetupParams.GenerateManifests) { build.AddProperty("GenerateManifests", Convert.ToString(SetupParams.GenerateManifests)); } string hostInBrowser = "false"; if (SetupParams.HostInBrowser) { hostInBrowser = "true"; } build.AddProperty("HostinBrowser", hostInBrowser); string localPath = SetupParams.LocalPath; if (String.IsNullOrEmpty(localPath)) { localPath = DirectorySW.GetCurrentDirectory(); } if (!IsLibrary() && SetupParams.TargetZone == "") { // This is for Full Trust Compilation string appManifest = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<asmv1:assembly manifestVersion=\"1.0\" xmlns=\"urn:schemas-microsoft-com:asm.v1\" xmlns:asmv1=\"urn:schemas-microsoft-com:asm.v1\" xmlns:asmv2=\"urn:schemas-microsoft-com:asm.v2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + " <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v2\">" + " <security>" + " <applicationRequestMinimum>" + " <PermissionSet class=\"System.Security.PermissionSet\" version=\"1\" Unrestricted=\"true\" ID=\"Custom\" SameSite=\"site\" />" + " <defaultAssemblyRequest permissionSetReference=\"Custom\" />" + " </applicationRequestMinimum>" + " </security>" + " </trustInfo>" + "</asmv1:assembly>"; string securityManifestFullTrust = "<Security>" + " <ApplicationRequestMinimum>" + " <PermissionSet ID=\"FT\" temp:Unrestricted=\"true\" />" + " <DefaultAssemblyRequest PermissionSetReference=\"FT\" />" + " </ApplicationRequestMinimum>" + "</Security>"; FileStreamSW fs = null; StreamWriterSW writer = null; if (!FileSW.Exists(app_manifest)) { try { string path = PathSW.Combine(localPath, app_manifest); fs = new FileStreamSW(path, FileMode.Create, FileAccess.Write); writer = new StreamWriterSW((Stream)fs.InnerObject); writer.Write(appManifest); } finally { if (writer != null) { writer.Close(); } if (fs != null) { fs.Close(); } } } if (!FileSW.Exists(SecurityManifestFullTrust)) { try { string path = PathSW.Combine(localPath, SecurityManifestFullTrust); fs = new FileStreamSW(path, FileMode.Create, FileAccess.Write); writer = new StreamWriterSW((Stream)fs.InnerObject); writer.Write(securityManifestFullTrust); } finally { if (writer != null) { writer.Close(); } if (fs != null) { fs.Close(); } } } build.AddProperty("TargetZone", "Custom"); build.AddItem("None", app_manifest); build.AddItem("None", SecurityManifestFullTrust); } build.AddProperty("AssemblyName", SetupParams.AssemblyName); build.AddProperty("OutputPath", SetupParams.OutputPath); build.AddProperty("RootNamespace", SetupParams.RootNamespace); build.AddProperty("UICulture", SetupParams.UICulture); if (!IsLibrary()) { build.AddItem("None", "ClickOnceTest.pfx"); build.AddProperty("SignManifests", "true"); build.AddProperty("ManifestKeyFile", "ClickOnceTest.pfx"); build.AddProperty("ManifestCertificateThumbprint", "cd582af19e477ae94a53102e0453e71b3c592a80"); } if (SetupParams.Language == Languages.CSharp) { build.AddImport(MSBuildDirectory + @"\Microsoft.CSharp.targets"); } else { build.AddImport(MSBuildDirectory + @"\Microsoft.VisualBasic.targets"); } build.AddImport(MSBuildDirectory + @"\Microsoft.WinFx.targets"); if (!String.IsNullOrEmpty(SetupParams.ApplicationDefinition)) { build.AddItem("ApplicationDefinition", SetupParams.ApplicationDefinition); } for (int i = 0; i < SetupParams.XamlPages.Count; i++) { build.AddItem("Page", SetupParams.XamlPages[i]); } for (int i = 0; i < SetupParams.CompileFiles.Count; i++) { build.AddItem("Compile", SetupParams.CompileFiles[i]); } for (int i = 0; i < SetupParams.Resources.Count; i++) { build.AddResource(SetupParams.Resources[i].FileName, SetupParams.Resources[i].FileStorage, ""); } for (int i = 0; i < SetupParams.Contents.Count; i++) { build.AddContent(SetupParams.Contents[i].FileName, SetupParams.Contents[i].CopyToOutputDirectory, ""); } for (int i = 0; i < SetupParams.References.Count; i++) { build.AddReference(SetupParams.References[i].FileName, "", SetupParams.References[i].HintPath, ""); } //HACK build.CommandLineArguements = "/t:Build"; if (saveProjFile) { build.SaveProjectFile = Path.Combine(localPath, "__CompilerServicesSave.proj"); } build.Build(); if (saveProjFile) { build.SaveProjectFile = Path.Combine(localPath, "__CompilerServicesSave.proj"); } if (build.OutputDirectory != null && !IsLibrary()) { string compiledExtension; if (SetupParams.HostInBrowser) { compiledExtension = ApplicationDeploymentHelper.BROWSER_APPLICATION_EXTENSION; } else { compiledExtension = ApplicationDeploymentHelper.STANDALONE_APPLICATION_EXTENSION; } if (SetupParams.GenerateManifests) { string fileToSign = PathSW.Combine(build.OutputDirectory, SetupParams.AssemblyName + compiledExtension); #if (!STRESS_RUNTIME) Microsoft.Test.Logging.GlobalLog.LogStatus("Signing file: " + fileToSign); #endif //MQ AvalonDeploymentHelper.SignManifest(fileToSign); } } return(build.UnhandledErrorsandWarningsList); }