From 4d9c33d9e4c5e263aec482aa0786bd7227280d6d Mon Sep 17 00:00:00 2001 From: Hugo Dahl Date: Wed, 2 Mar 2022 20:28:24 -0600 Subject: [PATCH 1/3] Break out of for loop on success Addresses item 1 of issue #726 --- src/Shared/Utilities.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Shared/Utilities.cs b/src/Shared/Utilities.cs index 9e375f66..c20f34a0 100644 --- a/src/Shared/Utilities.cs +++ b/src/Shared/Utilities.cs @@ -19,6 +19,7 @@ internal static void FileOperationWithRetry(Action operation) try { operation(); + break; } catch (IOException ex) when (ex.HResult == ProcessCannotAccessFileHR && retriesLeft > 0) { From b6e44c3bf9cf0162883638828caea08ccacc3f74 Mon Sep 17 00:00:00 2001 From: Hugo Dahl Date: Wed, 2 Mar 2022 20:38:28 -0600 Subject: [PATCH 2/3] Use 'File.AppendLine()' to generate output Let the 'System.IO.File' provider handle newlines between entries rather than manually inserting them Addresses item 2 of #726 --- src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs b/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs index 48ca3bbf..f3931042 100644 --- a/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs +++ b/src/NerdBank.GitVersioning/CloudBuildServices/GitHubActions.cs @@ -28,7 +28,7 @@ internal class GitHubActions : ICloudBuild public IReadOnlyDictionary SetCloudBuildVariable(string name, string value, TextWriter stdout, TextWriter stderr) { - Utilities.FileOperationWithRetry(() => File.AppendAllText(EnvironmentFile, $"{Environment.NewLine}{name}={value}{Environment.NewLine}")); + Utilities.FileOperationWithRetry(() => File.AppendAllLines(EnvironmentFile, new [] {$"{name}={value}"})); return GetDictionaryFor(name, value); } From be4a5a74d705d876b1f0e28debd8c49147b78e19 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 14 Mar 2022 17:15:11 -0600 Subject: [PATCH 3/3] Fix NullReferenceException thrown when PATH is empty/missing --- src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs b/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs index f3bb3e17..7ba03cb6 100644 --- a/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs +++ b/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs @@ -56,7 +56,7 @@ public override bool Execute() // On .NET Framework (on Windows), we find native binaries by adding them to our PATH. if (this.UnmanagedDllDirectory is not null) { - string pathEnvVar = Environment.GetEnvironmentVariable("PATH"); + string pathEnvVar = Environment.GetEnvironmentVariable("PATH") ?? string.Empty; string[] searchPaths = pathEnvVar.Split(Path.PathSeparator); if (!searchPaths.Contains(this.UnmanagedDllDirectory, StringComparer.OrdinalIgnoreCase)) {