Skip to content

Commit 33489da

Browse files
committed
Print and store versions at end of every build
This makes it easier to visually confirm what was built: Build Info: SDK Version: 5.0.202 ASP.NET Core Version: 5.0.5 Runtime Version: 5.0.5 And also stores these values in named version files for later use. Fixes: dotnet#600
1 parent 7422fa7 commit 33489da

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
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="WriteVersionsToFile"
142+
AfterTargets="Build">
143+
144+
<ItemGroup>
145+
<FinalCliTarball Include="$(BaseOutputPath)**/dotnet-sdk*$(TarBallExtension)" />
146+
</ItemGroup>
147+
148+
<PropertyGroup>
149+
<FinalCliTarballPath>%(FinalCliTarball.Identity)</FinalCliTarballPath>
150+
<ExtractedPath>$(BaseOutputPath)\extracted-sdk\</ExtractedPath>
151+
</PropertyGroup>
152+
153+
<MakeDir Directories="$(ExtractedPath)" />
154+
155+
<Exec Command="tar xf $(FinalCliTarballPath) -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" >
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
34+
var pathToDotNet = Path.Join(SdkRootDirectory, "dotnet");
35+
SdkVersion = ExecuteDotNetCommand(SdkRootDirectory,
36+
pathToDotNet,
37+
new List<string> { "--list-sdks" })
38+
.First()
39+
.Split(" ")
40+
.First();
41+
AspNetCoreVersion = ExecuteDotNetCommand(SdkRootDirectory,
42+
pathToDotNet,
43+
new List<string> { "--list-runtimes" })
44+
.Where(line => line.Contains("Microsoft.AspNetCore.App"))
45+
.First()
46+
.Split(" ")
47+
.Skip(1)
48+
.First();
49+
RuntimeVersion = ExecuteDotNetCommand(SdkRootDirectory,
50+
pathToDotNet,
51+
new List<string> { "--list-runtimes"})
52+
.Where(line => line.Contains("Microsoft.NETCore.App"))
53+
.First()
54+
.Split(" ")
55+
.Skip(1)
56+
.First();
57+
58+
return true;
59+
}
60+
61+
/// <summary>
62+
/// Executes a dotnet command and returns the result.
63+
/// </summary>
64+
/// <param name="workingDirectory">The working directory for the dotnet command.</param>
65+
/// <param name="command">The complete path to the dotnet command to execute.</param>
66+
/// <param name="argumentList">The arguments to the dotnet command to execute.</param>
67+
/// <returns>An array of the output lines of the dotnet command.</returns>
68+
private string[] ExecuteDotNetCommand(string workingDirectory, string command, List<string> argumentList)
69+
{
70+
string[] returnData;
71+
Process _process = new Process();
72+
_process.StartInfo.FileName = command;
73+
foreach (string argument in argumentList)
74+
{
75+
_process.StartInfo.ArgumentList.Add(argument);
76+
}
77+
_process.StartInfo.WorkingDirectory = workingDirectory;
78+
_process.StartInfo.RedirectStandardOutput = true;
79+
_process.StartInfo.UseShellExecute = false;
80+
_process.Start();
81+
returnData = _process.StandardOutput.ReadToEnd().Split('\n');
82+
_process.WaitForExit();
83+
return returnData;
84+
}
85+
86+
}
87+
}

0 commit comments

Comments
 (0)