-
Notifications
You must be signed in to change notification settings - Fork 341
Specifying environment variables in RunSettings file #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c5fc564
9ac75ee
1638717
9bec351
d2b2781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities | |
| using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Dynamic; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Text; | ||
|
|
@@ -36,6 +37,7 @@ public class InferRunSettingsHelper | |
| private const string TargetFrameworkNodePath = @"/RunSettings/RunConfiguration/TargetFrameworkVersion"; | ||
| private const string ResultsDirectoryNodePath = @"/RunSettings/RunConfiguration/ResultsDirectory"; | ||
| private const string TargetDeviceNodePath = @"/RunSettings/RunConfiguration/TargetDevice"; | ||
| private const string EnvironmentVariablesNodePath = @"/RunSettings/RunConfiguration/EnvironmentVariables"; | ||
| private const string multiTargettingForwardLink = @"http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409"; | ||
|
|
||
| // To make things compatible for older runsettings | ||
|
|
@@ -377,6 +379,50 @@ private static List<string> GetNodeAttributes(XPathNavigator node) | |
| return null; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a dictionary of environment variables given in run settings | ||
| /// </summary> | ||
| /// <param name="runsettingsXml">The run settings xml string</param> | ||
| /// <returns>Environment Variables Dictionary</returns> | ||
| public static Dictionary<string, string> GetEnvironmentVariables(string runSettings) | ||
| { | ||
| Dictionary<string, string> environmentVariables = null; | ||
| try | ||
| { | ||
| using (var stream = new StringReader(runSettings)) | ||
| using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings)) | ||
| { | ||
| var document = new XmlDocument(); | ||
| document.Load(reader); | ||
| var runSettingsNavigator = document.CreateNavigator(); | ||
|
|
||
| var node = runSettingsNavigator.SelectSingleNode(EnvironmentVariablesNodePath); | ||
| if (node == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| environmentVariables = new Dictionary<string, string>(); | ||
| var childNodes = node.SelectChildren(XPathNodeType.Element); | ||
|
|
||
| while (childNodes.MoveNext()) | ||
| { | ||
| if (!environmentVariables.ContainsKey(childNodes.Current.Name)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You can use TryAdd, instead of checking and then adding. |
||
| { | ||
| environmentVariables.Add(childNodes.Current.Name, childNodes.Current?.Value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| EqtTrace.Error("Error while trying to read environment variables settings. Message: {0}", ex.ToString()); | ||
| return null; | ||
| } | ||
|
|
||
| return environmentVariables; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Updates the <c>RunConfiguration.TargetPlatform</c> value for a run settings. if the value is already set, behavior depends on overwrite. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Diagnostics.Contracts; | ||
| using System.Globalization; | ||
|
|
@@ -137,6 +138,12 @@ public void Initialize(string argument) | |
| this.runSettingsManager.AddDefaultRunSettings(); | ||
|
|
||
| this.commandLineOptions.SettingsFile = argument; | ||
|
|
||
| if (this.runSettingsManager.QueryRunSettingsNode("RunConfiguration.EnvironmentVariables") != null) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Constants ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not available |
||
| { | ||
| this.commandLineOptions.InIsolation = true; | ||
| this.runSettingsManager.UpdateRunSettingsNode(InIsolationArgumentExecutor.RunSettingsPath, "true"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why is this required if the CLI option is already set.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/microsoft/vstest/blob/master/src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs#L244 This checks inisolation node from runsettings. |
||
| } | ||
| } | ||
| catch (XmlException exception) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.