diff --git a/src/core-sdk-tasks/GetDependencyInfo.cs b/src/core-sdk-tasks/GetDependencyInfo.cs new file mode 100644 index 000000000..909140113 --- /dev/null +++ b/src/core-sdk-tasks/GetDependencyInfo.cs @@ -0,0 +1,55 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using System.Linq; +using System.Xml.Linq; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Microsoft.DotNet.Cli.Build +{ + /// + /// Gets version and commit of a dependency by its name + /// from eng/Version.Details.xml + /// + public class GetDependencyInfo : Task + { + [Required] + public string VersionDetailsXmlFile { get; set; } + + [Required] + public string DependencyName { get; set; } + + [Output] + public string DependencyVersion { get; set; } + + [Output] + public string DependencyCommit { get; set; } + + public override bool Execute() + { + try + { + XDocument document = XDocument.Load(VersionDetailsXmlFile); + XElement dependency = document + .Element("Dependencies")? + .Element("ProductDependencies")? + .Elements("Dependency") + .FirstOrDefault(d => DependencyName.Equals(d.Attribute("Name")?.Value)); + + if (dependency != null) + { + DependencyVersion = dependency.Attribute("Version")?.Value; + DependencyCommit = dependency.Element("Sha")?.Value; + } + } + catch (Exception ex) + { + Log.LogWarning($"GetComponentCommit failed for VersionDetailsXmlFile={VersionDetailsXmlFile}, DependencyName={DependencyName}: {ex}"); + } + return true; + } + } +} diff --git a/src/redist/targets/BuildCoreSdkTasks.targets b/src/redist/targets/BuildCoreSdkTasks.targets index f89f2297f..e93fd0d06 100644 --- a/src/redist/targets/BuildCoreSdkTasks.targets +++ b/src/redist/targets/BuildCoreSdkTasks.targets @@ -39,5 +39,6 @@ + diff --git a/src/redist/targets/GenerateBundledVersions.targets b/src/redist/targets/GenerateBundledVersions.targets index 84863779b..489f215da 100644 --- a/src/redist/targets/GenerateBundledVersions.targets +++ b/src/redist/targets/GenerateBundledVersions.targets @@ -16,9 +16,20 @@ Overwrite="true" Encoding="ASCII" /> + + + + + +