diff --git a/test/Templates.Test/Helpers/TemplatePackageInstaller.cs b/test/Templates.Test/Helpers/TemplatePackageInstaller.cs index 2de1116368..47cea247d7 100644 --- a/test/Templates.Test/Helpers/TemplatePackageInstaller.cs +++ b/test/Templates.Test/Helpers/TemplatePackageInstaller.cs @@ -73,21 +73,26 @@ namespace Templates.Test.Helpers private static void VerifyCannotFindTemplate(ITestOutputHelper output, string templateName) { // Verify we really did remove the previous templates - var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D")); + var tempDir = Path.Combine(Directory.GetCurrentDirectory(), Guid.NewGuid().ToString("D")); Directory.CreateDirectory(tempDir); - var proc = ProcessEx.Run( - output, - tempDir, - "dotnet", - $"new \"{templateName}\""); - proc.WaitForExit(assertSuccess: false); - if (!proc.Error.Contains($"No templates matched the input template name: {templateName}.")) + try { - throw new InvalidOperationException($"Failed to uninstall previous templates. The template '{templateName}' could still be found."); + var proc = ProcessEx.Run( + output, + tempDir, + "dotnet", + $"new \"{templateName}\""); + proc.WaitForExit(assertSuccess: false); + if (!proc.Error.Contains($"No templates matched the input template name: {templateName}.")) + { + throw new InvalidOperationException($"Failed to uninstall previous templates. The template '{templateName}' could still be found."); + } + } + finally + { + Directory.Delete(tempDir); } - - Directory.Delete(tempDir); } private static string FindAncestorDirectoryContaining(string filename)