diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 33f721e1e6..c9f8505b7a 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -725,14 +725,20 @@ protected string BuildMultipleAssemblyPath(params string[] assetNames) return string.Join(" ", assertFullPaths); } + /// + /// Creates an unique temporary directory for storing test results. + /// + /// + /// Path of the created directory. + /// protected static string GetResultsDirectory() { - var directoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); - - if (!Directory.Exists(directoryPath)) - { - Directory.CreateDirectory(directoryPath); - } + // AGENT_TEMPDIRECTORY is AzureDevops variable, which is set to path + // that is cleaned up after every job. This is preferable to use over + // just the normal temp. + var temp = Environment.GetEnvironmentVariable("AGENT_TEMPDIRECTORY") ?? Path.GetTempPath(); + var directoryPath = Path.Combine(temp, Guid.NewGuid().ToString("n")); + Directory.CreateDirectory(directoryPath); return directoryPath; }