diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 81c4390a78..ff35679308 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -15,7 +15,7 @@
}
},
"extensions": [
- "ms-dotnettools.csharp",
+ "ms-dotnettools.csdevkit",
"ms-vscode.powershell",
"github.vscode-pull-request-github",
"davidanson.vscode-markdownlint",
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index 48a037f99d..fc2c6b226c 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -1,6 +1,6 @@
{
"recommendations": [
- "ms-dotnettools.csharp",
+ "ms-dotnettools.csdevkit",
"ms-vscode.powershell",
"github.vscode-pull-request-github",
"davidanson.vscode-markdownlint",
diff --git a/docs/CHANGELOG-v3.md b/docs/CHANGELOG-v3.md
index 84c070b4d7..8372f9bb33 100644
--- a/docs/CHANGELOG-v3.md
+++ b/docs/CHANGELOG-v3.md
@@ -30,8 +30,8 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers
What's changed since pre-release v3.0.0-B0153:
- Engineering:
- - Bump System.Drawing.Common to v8.0.4.
- [#1790](https://github.com/microsoft/PSRule/pull/1790)
+ - Bump System.Drawing.Common to v8.0.5.
+ [#1817](https://github.com/microsoft/PSRule/pull/1817)
- Bump Bump xunit to v2.8.0.
[#1809](https://github.com/microsoft/PSRule/pull/1809)
- Bump xunit.runner.visualstudio to v2.8.0.
diff --git a/src/PSRule.BuildTool/PSRule.BuildTool.csproj b/src/PSRule.BuildTool/PSRule.BuildTool.csproj
index eb221a3fbf..2d04e1879f 100644
--- a/src/PSRule.BuildTool/PSRule.BuildTool.csproj
+++ b/src/PSRule.BuildTool/PSRule.BuildTool.csproj
@@ -11,7 +11,7 @@
-
+
diff --git a/src/PSRule.BuildTool/packages.lock.json b/src/PSRule.BuildTool/packages.lock.json
index 1de64498b0..b521aa51d0 100644
--- a/src/PSRule.BuildTool/packages.lock.json
+++ b/src/PSRule.BuildTool/packages.lock.json
@@ -30,9 +30,9 @@
},
"System.Drawing.Common": {
"type": "Direct",
- "requested": "[8.0.3, )",
- "resolved": "8.0.3",
- "contentHash": "oDE9duAtHhxYJM2bsOlZCLBKdorU9DTV1tw7Mlc+VIT7HgwO5ddfOHk/An8C+fAS9oKdmn2PaIA5t1b484uz8g==",
+ "requested": "[8.0.5, )",
+ "resolved": "8.0.5",
+ "contentHash": "n55wb6rL8YG254AG+SfQOSQencrcnpKAAcYyEcvBuO2pob7ltXuZ5skBBdvLJOLVPKd1Ya8+8ColIM5AtBo5ww==",
"dependencies": {
"Microsoft.Win32.SystemEvents": "8.0.0"
}
diff --git a/src/PSRule/Common/ExternalToolHelper.cs b/src/PSRule/Common/ExternalToolHelper.cs
index 11b388a4d0..c55918415b 100644
--- a/src/PSRule/Common/ExternalToolHelper.cs
+++ b/src/PSRule/Common/ExternalToolHelper.cs
@@ -14,18 +14,15 @@ internal sealed class ExternalTool : IDisposable
private readonly AutoResetEvent _ErrorWait;
private readonly AutoResetEvent _OutputWait;
private readonly int _Interval;
- private readonly int _Timeout;
private readonly string _BinaryPath;
private bool _Disposed;
- private ExternalTool(string binaryPath, int timeout, string version = null)
+ private ExternalTool(string binaryPath)
{
_Output = new StringBuilder();
_Error = new StringBuilder();
_Interval = 1000;
- _Timeout = timeout;
_BinaryPath = binaryPath;
-
_ErrorWait = new AutoResetEvent(false);
_OutputWait = new AutoResetEvent(false);
}
@@ -37,7 +34,7 @@ internal static ExternalTool Get(string defaultPath, string binary)
if (!TryPathFromDefault(defaultPath, binary, out var binaryPath) && !TryPathFromEnvironment(binary, out binaryPath))
return null;
- return new ExternalTool(binaryPath, 0, null);
+ return new ExternalTool(binaryPath);
}
private static bool TryPathFromDefault(string defaultPath, string binary, out string binaryPath)
@@ -47,30 +44,28 @@ private static bool TryPathFromDefault(string defaultPath, string binary, out st
public bool WaitForExit(string args, out int exitCode)
{
- var startInfo = new ProcessStartInfo(_BinaryPath, args)
+ _Process = new Process
{
- CreateNoWindow = true,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- UseShellExecute = false,
- WorkingDirectory = Environment.GetWorkingPath(),
+ StartInfo = new ProcessStartInfo(_BinaryPath, args)
+ {
+ CreateNoWindow = true,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ WorkingDirectory = Environment.GetWorkingPath(),
+ }
};
- _Process = Process.Start(startInfo);
- _Process.ErrorDataReceived += Bicep_ErrorDataReceived;
- _Process.OutputDataReceived += Bicep_OutputDataReceived;
-
- _Process.BeginErrorReadLine();
- _Process.BeginOutputReadLine();
+ _Process.ErrorDataReceived += Tool_ErrorDataReceived;
+ _Process.OutputDataReceived += Tool_OutputDataReceived;
_ErrorWait.Reset();
_OutputWait.Reset();
- if (!_Process.HasExited)
- {
- var timeoutCount = 0;
- while (!_Process.WaitForExit(_Interval) && !_Process.HasExited && timeoutCount < _Timeout)
- timeoutCount++;
- }
+ _Process.Start();
+ _Process.BeginErrorReadLine();
+ _Process.BeginOutputReadLine();
+
+ _Process.WaitForExit();
exitCode = _Process.HasExited ? _Process.ExitCode : -1;
return _Process.HasExited && _ErrorWait.WaitOne(_Interval) && _OutputWait.WaitOne();
@@ -78,15 +73,21 @@ public bool WaitForExit(string args, out int exitCode)
public string GetOutput()
{
- return _Output.ToString();
+ lock (_Output)
+ {
+ return _Output.ToString();
+ }
}
public string GetError()
{
- return _Error.ToString();
+ lock (_Error)
+ {
+ return _Error.ToString();
+ }
}
- private void Bicep_OutputDataReceived(object sender, DataReceivedEventArgs e)
+ private void Tool_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data == null)
{
@@ -94,11 +95,14 @@ private void Bicep_OutputDataReceived(object sender, DataReceivedEventArgs e)
}
else
{
- _Output.AppendLine(e.Data);
+ lock (_Output)
+ {
+ _Output.AppendLine(e.Data);
+ }
}
}
- private void Bicep_ErrorDataReceived(object sender, DataReceivedEventArgs e)
+ private void Tool_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data == null)
{
@@ -107,8 +111,14 @@ private void Bicep_ErrorDataReceived(object sender, DataReceivedEventArgs e)
else
{
var errors = GetErrorLine(e.Data);
- for (var i = 0; i < errors.Length; i++)
- _Error.AppendLine(errors[i]);
+ if (errors.Length == 0)
+ return;
+
+ lock (_Error)
+ {
+ for (var i = 0; i < errors.Length; i++)
+ _Error.AppendLine(errors[i]);
+ }
}
}
@@ -161,8 +171,14 @@ private void Dispose(bool disposing)
_OutputWait.Dispose();
_Process.Dispose();
}
- _Error.Clear();
- _Output.Clear();
+ lock (_Error)
+ {
+ _Error.Clear();
+ }
+ lock (_Output)
+ {
+ _Output.Clear();
+ }
_Disposed = true;
}
}