From cc65ddfa280e41dc2e9088a5b8c334e1eed53192 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Mon, 8 Aug 2016 15:08:20 -0700 Subject: [PATCH] Updated ApplicationDeployer to conditionally delete published application folder --- .../Common/DeploymentParameters.cs | 2 ++ .../Deployers/ApplicationDeployer.cs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs b/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs index ceba263673..8ff17cdf24 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Common/DeploymentParameters.cs @@ -81,6 +81,8 @@ namespace Microsoft.AspNetCore.Server.Testing /// public bool PublishApplicationBeforeDeployment { get; set; } + public bool DeletePublishedApplicationOnDispose { get; set; } = true; + public ApplicationType ApplicationType { get; set; } public string PublishedApplicationRootPath { get; set; } diff --git a/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs index 089efeff76..17341f06d9 100644 --- a/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs +++ b/src/Microsoft.AspNetCore.Server.Testing/Deployers/ApplicationDeployer.cs @@ -82,14 +82,23 @@ namespace Microsoft.AspNetCore.Server.Testing protected void CleanPublishedOutput() { - try + if (DeploymentParameters.DeletePublishedApplicationOnDispose) { - // We've originally published the application in a temp folder. We need to delete it. - Directory.Delete(DeploymentParameters.PublishedApplicationRootPath, true); + try + { + // We've originally published the application in a temp folder. We need to delete it. + Directory.Delete(DeploymentParameters.PublishedApplicationRootPath, true); + } + catch (Exception exception) + { + Logger.LogWarning($"Failed to delete directory : {exception.Message}"); + } } - catch (Exception exception) + else { - Logger.LogWarning($"Failed to delete directory : {exception.Message}"); + Logger.LogWarning( + "Skipping deleting the locally published folder as property " + + $"'{nameof(DeploymentParameters.DeletePublishedApplicationOnDispose)}' is set to 'false'."); } }