Skip to content

Commit a298572

Browse files
Merge pull request #2157 from omajid/5.0-show-build-version-info
[release/5.0] Print and store versions at end of every build
2 parents 701e306 + aa23c54 commit a298572

File tree

3 files changed

+135
-5
lines changed

3 files changed

+135
-5
lines changed

build.proj

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WriteUsageBurndownData" />
66
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" />
77
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="DownloadFileSB" />
8+
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ParseDotNetVersions" />
89

910
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
1011

@@ -137,6 +138,46 @@
137138
<WriteLinesToFile File="$(CompletedSemaphorePath)ReportPoisonUsage.complete" Overwrite="true" />
138139
</Target>
139140

141+
<Target Name="VerifyAndWriteVersionsToFile"
142+
AfterTargets="Build">
143+
144+
<ItemGroup>
145+
<FinalSdkTarball Include="$(OutputPath)\dotnet-sdk-$(MajorVersion)*$(TarBallExtension)" />
146+
</ItemGroup>
147+
148+
<PropertyGroup>
149+
<!-- Shared path with smoke-test.sh -->
150+
<ExtractedPath>$(BaseOutputPath)\builtCli\</ExtractedPath>
151+
</PropertyGroup>
152+
153+
<MakeDir Directories="$(ExtractedPath)" />
154+
155+
<Exec Command="tar xf @(FinalSdkTarball) -C $(ExtractedPath)" />
156+
157+
<ParseDotNetVersions SdkRootDirectory="$(ExtractedPath)">
158+
<Output TaskParameter="SdkVersion" PropertyName="BuiltSdkVersion" />
159+
<Output TaskParameter="AspNetCoreVersion" PropertyName="BuiltAspNetCoreVersion" />
160+
<Output TaskParameter="RuntimeVersion" PropertyName="BuiltRuntimeVersion" />
161+
</ParseDotNetVersions>
162+
163+
<Message Text="Build Info:" Importance="High"/>
164+
<Message Text=" SDK Version: $(BuiltSdkVersion)" Importance="High"/>
165+
<Message Text=" ASP.NET Core Version: $(BuiltAspNetCoreVersion)" Importance="High"/>
166+
<Message Text=" Runtime Version: $(BuiltRuntimeVersion)" Importance="High"/>
167+
168+
<WriteLinesToFile Lines="$(BuiltSdkVersion)" File="$(BaseOutputPath)\build-info\SdkVersion.txt" Overwrite="True" />
169+
<WriteLinesToFile Lines="$(BuiltAspNetCoreVersion)" File="$(BaseOutputPath)\build-info\AspNetCoreVersion.txt" Overwrite="True" />
170+
<WriteLinesToFile Lines="$(BuiltRuntimeVersion)" File="$(BaseOutputPath)\build-info\RuntimeVersion.txt" Overwrite="True" />
171+
172+
<Error Text="Mismatch in SDK version between what was built ($(BuiltSdkVersion)) and what's in Version.props ($(SdkProductVersion))"
173+
Condition="'$(BuiltSdkVersion)' != '$(SdkProductVersion)'" />
174+
<Error Text="Mismatch in ASP.NET Core version between what was built ($(BuiltAspNetCoreVersion)) and what's in Version.props ($(AspNetCoreProductVersion))"
175+
Condition="'$(BuiltAspNetCoreVersion)' != '$(AspNetCoreProductVersion)'" />
176+
<Error Text="Mismatch in Runtime version between what was built ($(BuiltRuntimeVersion)) and what's in Version.props ($(RuntimeProductVersion))"
177+
Condition="'$(BuiltRuntimeVersion)' != '$(RuntimeProductVersion)'" />
178+
179+
</Target>
180+
140181
<Target Name="GeneratePrebuiltBurndownData"
141182
Inputs="$(MSBuildProjectFullPath)"
142183
Outputs="$(CompletedSemaphorePath)GeneratePrebuiltBurndownData.complete" >

smoke-test.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ excludeLocalTests=false
5151
excludeOnlineTests=false
5252
devCertsVersion="$DEV_CERTS_VERSION_DEFAULT"
5353
testingDir="$SCRIPT_ROOT/testing-smoke"
54-
cliDir="$testingDir/builtCli"
54+
# Shared path with build.proj
55+
cliDir="$SCRIPT_ROOT/artifacts/builtCli"
5556
logFile="$testingDir/smoke-test.log"
5657
restoredPackagesDir="$testingDir/packages"
5758
testingHome="$testingDir/home"
@@ -613,11 +614,14 @@ echo "<Project />" | tee Directory.Build.props > Directory.Build.targets
613614

614615
# Unzip dotnet if the dotnetDir is not specified
615616
if [ "$dotnetDir" == "" ]; then
616-
OUTPUT_DIR="$SCRIPT_ROOT/artifacts/$buildArch/$configuration/"
617-
DOTNET_TARBALL="$(ls "${OUTPUT_DIR}${TARBALL_PREFIX}${VERSION_PREFIX}"*)"
617+
# It's possible that build.proj extracted the just-built dotnet tarball for other processing already
618+
if [ ! -d "$cliDir" ]; then
619+
OUTPUT_DIR="$SCRIPT_ROOT/artifacts/$buildArch/$configuration/"
620+
DOTNET_TARBALL="$(ls "${OUTPUT_DIR}${TARBALL_PREFIX}${VERSION_PREFIX}"*)"
618621

619-
mkdir -p "$cliDir"
620-
tar xzf "$DOTNET_TARBALL" -C "$cliDir"
622+
mkdir -p "$cliDir"
623+
tar xzf "$DOTNET_TARBALL" -C "$cliDir"
624+
fi
621625
dotnetDir="$cliDir"
622626
else
623627
if ! [[ "$dotnetDir" = /* ]]; then
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Xml.Linq;
11+
using Microsoft.Build.Framework;
12+
using Microsoft.Build.Utilities;
13+
14+
namespace Microsoft.DotNet.Build.Tasks
15+
{
16+
/*
17+
* This task parses the versions in a .NET SDK
18+
*/
19+
public class ParseDotNetVersions : Task
20+
{
21+
[Required]
22+
public string SdkRootDirectory { get; set; }
23+
24+
[Output]
25+
public string SdkVersion { get; set; }
26+
[Output]
27+
public string AspNetCoreVersion { get; set; }
28+
[Output]
29+
public string RuntimeVersion { get; set; }
30+
31+
public override bool Execute()
32+
{
33+
var pathToDotNet = Path.Join(SdkRootDirectory, "dotnet");
34+
35+
SdkVersion = ExecuteDotNetCommand(SdkRootDirectory,
36+
pathToDotNet,
37+
new List<string> { "--list-sdks" })
38+
.First()
39+
.Split(" ")
40+
.First();
41+
42+
var runtimesOutput = ExecuteDotNetCommand(SdkRootDirectory,
43+
pathToDotNet,
44+
new List<string> { "--list-runtimes" });
45+
46+
AspNetCoreVersion = runtimesOutput
47+
.First(line => line.Contains("Microsoft.AspNetCore.App"))
48+
.Split(" ")
49+
.ElementAt(1);
50+
51+
RuntimeVersion = runtimesOutput
52+
.First(line => line.Contains("Microsoft.NETCore.App"))
53+
.Split(" ")
54+
.ElementAt(1);
55+
56+
return true;
57+
}
58+
59+
/// <summary>
60+
/// Executes a dotnet command and returns the result.
61+
/// </summary>
62+
/// <param name="workingDirectory">The working directory for the dotnet command.</param>
63+
/// <param name="command">The complete path to the dotnet command to execute.</param>
64+
/// <param name="argumentList">The arguments to the dotnet command to execute.</param>
65+
/// <returns>An array of the output lines of the dotnet command.</returns>
66+
private string[] ExecuteDotNetCommand(string workingDirectory, string command, List<string> argumentList)
67+
{
68+
string[] returnData;
69+
Process _process = new Process();
70+
_process.StartInfo.FileName = command;
71+
foreach (string argument in argumentList)
72+
{
73+
_process.StartInfo.ArgumentList.Add(argument);
74+
}
75+
_process.StartInfo.WorkingDirectory = workingDirectory;
76+
_process.StartInfo.RedirectStandardOutput = true;
77+
_process.StartInfo.UseShellExecute = false;
78+
_process.Start();
79+
returnData = _process.StandardOutput.ReadToEnd().Split(Environment.NewLine);
80+
_process.WaitForExit();
81+
return returnData;
82+
}
83+
84+
}
85+
}

0 commit comments

Comments
 (0)