diff --git a/build.proj b/build.proj index b678891bbe..c223878e1a 100644 --- a/build.proj +++ b/build.proj @@ -5,6 +5,7 @@ + @@ -137,6 +138,46 @@ + + + + + + + + + $(BaseOutputPath)\builtCli\ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/smoke-test.sh b/smoke-test.sh index ab6966b3e2..d60de83143 100755 --- a/smoke-test.sh +++ b/smoke-test.sh @@ -51,7 +51,8 @@ excludeLocalTests=false excludeOnlineTests=false devCertsVersion="$DEV_CERTS_VERSION_DEFAULT" testingDir="$SCRIPT_ROOT/testing-smoke" -cliDir="$testingDir/builtCli" +# Shared path with build.proj +cliDir="$SCRIPT_ROOT/artifacts/builtCli" logFile="$testingDir/smoke-test.log" restoredPackagesDir="$testingDir/packages" testingHome="$testingDir/home" @@ -611,11 +612,14 @@ echo "" | tee Directory.Build.props > Directory.Build.targets # Unzip dotnet if the dotnetDir is not specified if [ "$dotnetDir" == "" ]; then - OUTPUT_DIR="$SCRIPT_ROOT/artifacts/$buildArch/$configuration/" - DOTNET_TARBALL="$(ls "${OUTPUT_DIR}${TARBALL_PREFIX}${VERSION_PREFIX}"*)" + # It's possible that build.proj extracted the just-built dotnet tarball for other processing already + if [ ! -d "$cliDir" ]; then + OUTPUT_DIR="$SCRIPT_ROOT/artifacts/$buildArch/$configuration/" + DOTNET_TARBALL="$(ls "${OUTPUT_DIR}${TARBALL_PREFIX}${VERSION_PREFIX}"*)" - mkdir -p "$cliDir" - tar xzf "$DOTNET_TARBALL" -C "$cliDir" + mkdir -p "$cliDir" + tar xzf "$DOTNET_TARBALL" -C "$cliDir" + fi dotnetDir="$cliDir" else if ! [[ "$dotnetDir" = /* ]]; then diff --git a/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/ParseDotNetVersions.cs b/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/ParseDotNetVersions.cs new file mode 100755 index 0000000000..073120eae3 --- /dev/null +++ b/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/ParseDotNetVersions.cs @@ -0,0 +1,85 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Xml.Linq; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Microsoft.DotNet.Build.Tasks +{ + /* + * This task parses the versions in a .NET SDK + */ + public class ParseDotNetVersions : Task + { + [Required] + public string SdkRootDirectory { get; set; } + + [Output] + public string SdkVersion { get; set; } + [Output] + public string AspNetCoreVersion { get; set; } + [Output] + public string RuntimeVersion { get; set; } + + public override bool Execute() + { + var pathToDotNet = Path.Join(SdkRootDirectory, "dotnet"); + + SdkVersion = ExecuteDotNetCommand(SdkRootDirectory, + pathToDotNet, + new List { "--list-sdks" }) + .First() + .Split(" ") + .First(); + + var runtimesOutput = ExecuteDotNetCommand(SdkRootDirectory, + pathToDotNet, + new List { "--list-runtimes" }); + + AspNetCoreVersion = runtimesOutput + .First(line => line.Contains("Microsoft.AspNetCore.App")) + .Split(" ") + .ElementAt(1); + + RuntimeVersion = runtimesOutput + .First(line => line.Contains("Microsoft.NETCore.App")) + .Split(" ") + .ElementAt(1); + + return true; + } + + /// + /// Executes a dotnet command and returns the result. + /// + /// The working directory for the dotnet command. + /// The complete path to the dotnet command to execute. + /// The arguments to the dotnet command to execute. + /// An array of the output lines of the dotnet command. + private string[] ExecuteDotNetCommand(string workingDirectory, string command, List argumentList) + { + string[] returnData; + Process _process = new Process(); + _process.StartInfo.FileName = command; + foreach (string argument in argumentList) + { + _process.StartInfo.ArgumentList.Add(argument); + } + _process.StartInfo.WorkingDirectory = workingDirectory; + _process.StartInfo.RedirectStandardOutput = true; + _process.StartInfo.UseShellExecute = false; + _process.Start(); + returnData = _process.StandardOutput.ReadToEnd().Split(Environment.NewLine); + _process.WaitForExit(); + return returnData; + } + + } +}