diff --git a/eng/BootStrapMsBuild.props b/eng/BootStrapMsBuild.props index 51cb0bb8ead..299b89f609a 100644 --- a/eng/BootStrapMsBuild.props +++ b/eng/BootStrapMsBuild.props @@ -1,9 +1,6 @@ - + 8.0.302 @@ -12,7 +9,7 @@ $(ArtifactsBinDir)bootstrap\ $(BootstrapDestination)$(Platform)\ - $(BootstrapDestination)$(TargetFramework.ToLowerInvariant())\sdk\$(NetVersion)\ + $(BootstrapDestination)$(TargetFramework.ToLowerInvariant())\MSBuild\ diff --git a/eng/BootStrapMsBuild.targets b/eng/BootStrapMsBuild.targets index c9cf2f030be..3debcb95ad1 100644 --- a/eng/BootStrapMsBuild.targets +++ b/eng/BootStrapMsBuild.targets @@ -221,11 +221,11 @@ + DestinationFiles="@(FreshlyBuiltNetBinaries->'$(InstallDir)sdk\$(NetVersion)\%(RecursiveDir)%(Filename)%(Extension)')" /> diff --git a/eng/cibuild_bootstrapped_msbuild.ps1 b/eng/cibuild_bootstrapped_msbuild.ps1 index 2d34c6854d5..35ea847118c 100644 --- a/eng/cibuild_bootstrapped_msbuild.ps1 +++ b/eng/cibuild_bootstrapped_msbuild.ps1 @@ -78,7 +78,7 @@ try { if ($msbuildEngine -eq 'vs') { - $buildToolPath = Join-Path $bootstrapRoot "net472\sdk\Current\Bin\MSBuild.exe" + $buildToolPath = Join-Path $bootstrapRoot "net472\MSBuild\Current\Bin\MSBuild.exe" $buildToolCommand = ""; $buildToolFramework = "net472" } @@ -87,8 +87,7 @@ try { $buildToolPath = Join-Path $bootstrapRoot "net8.0\dotnet.exe" # Must be consistent with the version in BootStrapMsBuild.props - $netVersion="8.0.302" - $buildToolCommand = Join-Path $bootstrapRoot "net8.0\sdk" $netVersion "MSBuild.dll"; + $buildToolCommand = Join-Path $bootstrapRoot "net8.0\sdk\8.0.302\MSBuild.dll"; $buildToolFramework = "net8.0" } diff --git a/eng/cibuild_bootstrapped_msbuild.sh b/eng/cibuild_bootstrapped_msbuild.sh index e6d42eacbe8..d97ba471e7e 100755 --- a/eng/cibuild_bootstrapped_msbuild.sh +++ b/eng/cibuild_bootstrapped_msbuild.sh @@ -55,13 +55,13 @@ then fi bootstrapRoot="$Stage1Dir/bin/bootstrap" -# Must be consistent with the version in BootStrapMsBuild.props -netVersion="8.0.302" if [ $host_type = "core" ] then _InitializeBuildTool="$bootstrapRoot/net8.0/dotnet" - _InitializeBuildToolCommand="$bootstrapRoot/net8.0/sdk/$netVersion/MSBuild.dll" + + # Must be consistent with the version in BootStrapMsBuild.props + _InitializeBuildToolCommand="$bootstrapRoot/net8.0/sdk/8.0.302/MSBuild.dll" _InitializeBuildToolFramework="net8.0" else echo "Unsupported hostType ($host_type)" diff --git a/src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs b/src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs index a1c5ebf8df0..008a86887c3 100644 --- a/src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs +++ b/src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs @@ -7,8 +7,11 @@ using System.IO; using System.Net.Http; using System.Runtime.InteropServices; +using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using AsyncTasks = System.Threading.Tasks; + namespace MSBuild.Bootstrap.Utils.Tasks { public sealed class InstallDotNetCoreTask : Task @@ -23,18 +26,23 @@ public InstallDotNetCoreTask() Version = string.Empty; } + [Required] public string InstallDir { get; set; } + [Required] public string DotNetInstallScriptRootPath { get; set; } + [Required] public string Version { get; set; } + private bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + public override bool Execute() { ScriptExecutionSettings executionSettings = SetupScriptsExecutionSettings(); if (!File.Exists(executionSettings.ScriptsFullPath)) { - DownloadScript(executionSettings.ScriptName, executionSettings.ScriptsFullPath); + AsyncTasks.Task.Run(() => DownloadScriptAsync(executionSettings.ScriptName, executionSettings.ScriptsFullPath)).GetAwaiter().GetResult(); } MakeScriptExecutable(executionSettings.ScriptsFullPath); @@ -42,14 +50,14 @@ public override bool Execute() return RunScript(executionSettings); } - private async void DownloadScript(string scriptName, string scriptPath) + private async AsyncTasks.Task DownloadScriptAsync(string scriptName, string scriptPath) { using (HttpClient client = new HttpClient()) { - HttpResponseMessage response = await client.GetAsync($"{DotNetInstallBaseUrl}{scriptName}"); + HttpResponseMessage response = await client.GetAsync($"{DotNetInstallBaseUrl}{scriptName}").ConfigureAwait(false); if (response.IsSuccessStatusCode) { - string scriptContent = await response.Content.ReadAsStringAsync(); + string scriptContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (!string.IsNullOrEmpty(scriptContent)) { File.WriteAllText(scriptPath, scriptContent); @@ -84,11 +92,22 @@ private void MakeScriptExecutable(string scriptPath) { _ = process.Start(); process.WaitForExit(); + + if (process.ExitCode != 0) + { + string errors = process.StandardError.ReadToEnd() ?? string.Empty; + Log.LogError($"Install-scripts can not be made executable due to the errors: {errors}."); + } } } private bool RunScript(ScriptExecutionSettings executionSettings) { + if (Log.HasLoggedErrors) + { + return false; + } + using (Process process = new Process { StartInfo = executionSettings.StartInfo }) { bool started = process.Start(); @@ -102,7 +121,7 @@ private bool RunScript(ScriptExecutionSettings executionSettings) if (process.ExitCode != 0) { string errors = process.StandardError.ReadToEnd() ?? string.Empty; - Log.LogError("Install-scripts execution errors: " + errors); + Log.LogError($"Install-scripts execution errors: {errors}"); } } else @@ -114,19 +133,6 @@ private bool RunScript(ScriptExecutionSettings executionSettings) return !Log.HasLoggedErrors; } - private bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - - private struct ScriptExecutionSettings(string executableName, ProcessStartInfo startInfo, string scriptName, string scriptsFullPath) - { - public string ExecutableName { get; } = executableName; - - public ProcessStartInfo StartInfo { get; } = startInfo; - - public string ScriptName { get; } = scriptName; - - public string ScriptsFullPath { get; } = scriptsFullPath; - } - private ScriptExecutionSettings SetupScriptsExecutionSettings() { string scriptExtension = IsWindows ? "ps1" : "sh"; @@ -148,6 +154,17 @@ private ScriptExecutionSettings SetupScriptsExecutionSettings() return new ScriptExecutionSettings(executableName, startInfo, $"{ScriptName}.{scriptExtension}", scriptPath); } + + private struct ScriptExecutionSettings(string executableName, ProcessStartInfo startInfo, string scriptName, string scriptsFullPath) + { + public string ExecutableName { get; } = executableName; + + public ProcessStartInfo StartInfo { get; } = startInfo; + + public string ScriptName { get; } = scriptName; + + public string ScriptsFullPath { get; } = scriptsFullPath; + } } } diff --git a/src/MSBuild.Bootstrap/RedirectNuGetConsoleProcess.After.Microsoft.Common.targets b/src/MSBuild.Bootstrap/RedirectNuGetConsoleProcess.After.Microsoft.Common.targets deleted file mode 100644 index 3571d7e37f5..00000000000 --- a/src/MSBuild.Bootstrap/RedirectNuGetConsoleProcess.After.Microsoft.Common.targets +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - -