diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index 05d28b5e48..66d1f22a17 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -891,7 +891,13 @@ public static RunConfiguration FromXml(XmlReader reader) case "DotNetHostPath": XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); - runConfiguration.DotnetHostPath = reader.ReadElementContentAsString(); + string? dotnetHostPath = reader.ReadElementContentAsString(); + +#if !NETSTANDARD1_0 + dotnetHostPath = Environment.ExpandEnvironmentVariables(dotnetHostPath); +#endif + + runConfiguration.DotnetHostPath = dotnetHostPath; break; case "TreatNoTestsAsError": XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); diff --git a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs index d671781bdd..d637998729 100644 --- a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs @@ -16,6 +16,7 @@ public static class ClientUtilities { private const string TestSettingsFileXPath = "RunSettings/MSTest/SettingsFile"; private const string ResultsDirectoryXPath = "RunSettings/RunConfiguration/ResultsDirectory"; + private const string DotnetHostPathXPath = "RunSettings/RunConfiguration/DotNetHostPath"; private const string RunsettingsDirectory = "RunSettingsDirectory"; /// @@ -43,6 +44,12 @@ public static void FixRelativePathsInRunSettings(XmlDocument xmlDocument, string { FixNodeFilePath(resultsDirectoryNode, root); } + + var dotnetHostPathNode = xmlDocument.SelectSingleNode(DotnetHostPathXPath); + if (dotnetHostPathNode != null) + { + FixNodeFilePath(dotnetHostPathNode, root); + } } private static void AddRunSettingsDirectoryNode(XmlDocument doc, string path) diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs index 9807fed377..ecb2407bcf 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs @@ -195,7 +195,7 @@ public void FixRelativePathsInRunSettingsShouldExpandEnvironmentVariable() Environment.SetEnvironmentVariable("TEST_TEMP", Path.GetTempPath()); // using TEST_TEMP because TMP or TEMP, or HOME are not defined across all tested OSes // Using \\ instead of platform specifc path separator does not matter, because the paths are not interpreted by the OS. - var runSettingsXml = "%TEST_TEMP%\\results"; + var runSettingsXml = "%TEST_TEMP%\\results%TEST_TEMP%\\hostpath"; var doc = new XmlDocument(); doc.LoadXml(runSettingsXml); @@ -206,12 +206,15 @@ public void FixRelativePathsInRunSettingsShouldExpandEnvironmentVariable() var finalSettingsXml = doc.OuterXml; - var expectedPath = $"{Environment.GetEnvironmentVariable("TEST_TEMP")}\\results"; + var expectedResultsPath = $"{Environment.GetEnvironmentVariable("TEST_TEMP")}\\results"; + var expectedDotNetHostPath = $"{Environment.GetEnvironmentVariable("TEST_TEMP")}\\hostpath"; var expectedSettingsXml = string.Concat( "", - expectedPath, - "", + expectedResultsPath, + "", + expectedDotNetHostPath, + "", Path.GetDirectoryName(currentAssemblyLocation), "");