diff --git a/src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj b/src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj
index efcae382a9138e..46df0de863816b 100644
--- a/src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj
+++ b/src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj
@@ -20,7 +20,7 @@
-
+
-
+
diff --git a/src/tasks/AotCompilerTask/Utils.cs b/src/tasks/AotCompilerTask/Utils.cs
deleted file mode 100644
index a7c23d4132ac43..00000000000000
--- a/src/tasks/AotCompilerTask/Utils.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Text;
-using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
-
-internal class Utils
-{
- public static string RunProcess(
- string path,
- string args = "",
- IDictionary? envVars = null,
- string? workingDir = null,
- bool ignoreErrors = false)
- {
- LogInfo($"Running: {path} {args}");
- var outputBuilder = new StringBuilder();
- var errorBuilder = new StringBuilder();
- var processStartInfo = new ProcessStartInfo
- {
- FileName = path,
- UseShellExecute = false,
- CreateNoWindow = true,
- RedirectStandardError = true,
- RedirectStandardOutput = true,
- Arguments = args,
- };
-
- if (workingDir != null)
- {
- processStartInfo.WorkingDirectory = workingDir;
- }
-
- if (envVars != null)
- {
- foreach (KeyValuePair envVar in envVars)
- {
- processStartInfo.EnvironmentVariables[envVar.Key] = envVar.Value;
- }
- }
-
- Process process = Process.Start(processStartInfo)!;
- process.ErrorDataReceived += (sender, e) =>
- {
- LogError(e.Data);
- outputBuilder.AppendLine(e.Data);
- errorBuilder.AppendLine(e.Data);
- };
- process.OutputDataReceived += (sender, e) =>
- {
- LogInfo(e.Data);
- outputBuilder.AppendLine(e.Data);
- };
- process.BeginOutputReadLine();
- process.BeginErrorReadLine();
- process.WaitForExit();
- if (process.ExitCode != 0)
- {
- throw new Exception("Error: " + errorBuilder);
- }
-
- return outputBuilder.ToString().Trim('\r', '\n');
- }
-
- public static TaskLoggingHelper? Logger { get; set; }
-
- public static void LogInfo(string? msg)
- {
- if (msg != null)
- {
- Logger?.LogMessage(MessageImportance.High, msg);
- }
- }
-
- public static void LogError(string? msg)
- {
- if (msg != null)
- {
- Logger?.LogError(msg);
- }
- }
-}
diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs
index bae94a410d884f..6fa284ac069c09 100644
--- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs
+++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs
@@ -16,7 +16,7 @@ public class AppleAppBuilderTask : Task
/// The Apple OS we are targeting (iOS or tvOS)
///
[Required]
- public string TargetOS { get; set; } = Utils.TargetOS.iOS;
+ public string TargetOS { get; set; } = TargetNames.iOS;
///
/// ProjectName is used as an app name, bundleId and xcode project name
diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj
index 3d88864f90a1a1..04da7561d0d075 100644
--- a/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj
+++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.csproj
@@ -18,7 +18,8 @@
-
+
+
diff --git a/src/tasks/AppleAppBuilder/TargetOS.cs b/src/tasks/AppleAppBuilder/TargetOS.cs
new file mode 100644
index 00000000000000..c3e55db30d1141
--- /dev/null
+++ b/src/tasks/AppleAppBuilder/TargetOS.cs
@@ -0,0 +1,8 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+internal class TargetNames
+{
+ public const string iOS = "iOS";
+ public const string tvOS = "tvOS";
+}
diff --git a/src/tasks/AppleAppBuilder/Utils.cs b/src/tasks/AppleAppBuilder/Utils.cs
deleted file mode 100644
index 76ed8c1187e799..00000000000000
--- a/src/tasks/AppleAppBuilder/Utils.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Text;
-using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
-
-internal class Utils
-{
- public static string GetEmbeddedResource(string file)
- {
- using Stream stream = typeof(Utils).Assembly
- .GetManifestResourceStream("AppleAppBuilder.Templates." + file)!;
- using var reader = new StreamReader(stream);
- return reader.ReadToEnd();
- }
-
- public static string RunProcess(
- string path,
- string args = "",
- IDictionary? envVars = null,
- string? workingDir = null,
- bool ignoreErrors = false)
- {
- LogInfo($"Running: {path} {args}");
- var outputBuilder = new StringBuilder();
- var errorBuilder = new StringBuilder();
- var processStartInfo = new ProcessStartInfo
- {
- FileName = path,
- UseShellExecute = false,
- CreateNoWindow = true,
- RedirectStandardError = true,
- RedirectStandardOutput = true,
- Arguments = args,
- };
-
- if (workingDir != null)
- {
- processStartInfo.WorkingDirectory = workingDir;
- }
-
- if (envVars != null)
- {
- foreach (KeyValuePair envVar in envVars)
- {
- processStartInfo.EnvironmentVariables[envVar.Key] = envVar.Value;
- }
- }
-
- Process process = Process.Start(processStartInfo)!;
- process.ErrorDataReceived += (sender, e) =>
- {
- LogError(e.Data);
- outputBuilder.AppendLine(e.Data);
- errorBuilder.AppendLine(e.Data);
- };
- process.OutputDataReceived += (sender, e) =>
- {
- LogInfo(e.Data);
- outputBuilder.AppendLine(e.Data);
- };
- process.BeginOutputReadLine();
- process.BeginErrorReadLine();
- process.WaitForExit();
- if (process.ExitCode != 0)
- {
- throw new Exception("Error: " + errorBuilder);
- }
-
- return outputBuilder.ToString().Trim('\r', '\n');
- }
-
- public static TaskLoggingHelper? Logger { get; set; }
-
- public static void LogInfo(string? msg)
- {
- if (msg != null)
- {
- Logger?.LogMessage(MessageImportance.High, msg);
- }
- }
-
- public static void LogError(string? msg)
- {
- if (msg != null)
- {
- Logger?.LogError(msg);
- }
- }
-
- internal class TargetOS
- {
- public const string iOS = "iOS";
- public const string tvOS = "tvOS";
- }
-}
diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs
index 358e6b4fa78223..2d7d5a2ed59f86 100644
--- a/src/tasks/AppleAppBuilder/Xcode.cs
+++ b/src/tasks/AppleAppBuilder/Xcode.cs
@@ -15,7 +15,7 @@ internal class Xcode
public Xcode(string target)
{
Target = target;
- SysRoot = (Target == Utils.TargetOS.iOS) ?
+ SysRoot = (Target == TargetNames.iOS) ?
Utils.RunProcess("xcrun", "--sdk iphoneos --show-sdk-path") :
Utils.RunProcess("xcrun", "--sdk appletvos --show-sdk-path");
}
@@ -95,7 +95,7 @@ public string GenerateXCode(
}
string frameworks = "";
- if (Target == Utils.TargetOS.iOS)
+ if (Target == TargetNames.iOS)
{
frameworks = "\"-framework GSS\"";
}
@@ -164,7 +164,7 @@ public string BuildAppBundle(
if (architecture == "arm64")
{
- sdk = (Target == Utils.TargetOS.iOS) ? "iphoneos" : "appletvos";
+ sdk = (Target == TargetNames.iOS) ? "iphoneos" : "appletvos";
args.Append(" -arch arm64")
.Append(" -sdk " + sdk);
@@ -182,7 +182,7 @@ public string BuildAppBundle(
}
else
{
- sdk = (Target == Utils.TargetOS.iOS) ? "iphonesimulator" : "appletvsimulator";
+ sdk = (Target == TargetNames.iOS) ? "iphonesimulator" : "appletvsimulator";
args.Append(" -arch x86_64")
.Append(" -sdk " + sdk);
}
diff --git a/src/tasks/AndroidAppBuilder/Utils.cs b/src/tasks/Common/Utils.cs
similarity index 87%
rename from src/tasks/AndroidAppBuilder/Utils.cs
rename to src/tasks/Common/Utils.cs
index 93413b11663301..84511481aa09f4 100644
--- a/src/tasks/AndroidAppBuilder/Utils.cs
+++ b/src/tasks/Common/Utils.cs
@@ -11,6 +11,8 @@
internal class Utils
{
+ private static readonly object s_SyncObj = new object();
+
public static string GetEmbeddedResource(string file)
{
using Stream stream = typeof(Utils).Assembly
@@ -55,19 +57,25 @@ public static string RunProcess(
process.ErrorDataReceived += (sender, e) =>
{
- if (!silent)
+ lock (s_SyncObj)
{
- LogError(e.Data);
- outputBuilder.AppendLine(e.Data);
+ if (!silent)
+ {
+ LogError(e.Data);
+ outputBuilder.AppendLine(e.Data);
+ }
+ errorBuilder.AppendLine(e.Data);
}
- errorBuilder.AppendLine(e.Data);
};
process.OutputDataReceived += (sender, e) =>
{
- if (!silent)
+ lock (s_SyncObj)
{
- LogInfo(e.Data);
- outputBuilder.AppendLine(e.Data);
+ if (!silent)
+ {
+ LogInfo(e.Data);
+ outputBuilder.AppendLine(e.Data);
+ }
}
};
process.BeginOutputReadLine();