This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create framework assembly list file in .NET Core targeting pack (#5168)
* Create framework assembly list file * Fix FileUtilities private static style * Remove package ID prefix from PlatformManifest.txt * Proactively detect/report missing public key token
- Loading branch information
Showing
7 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// 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 Microsoft.Build.Framework; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
|
||
namespace Microsoft.DotNet.Build.Tasks | ||
{ | ||
public class CreateFrameworkListFile : BuildTask | ||
{ | ||
/// <summary> | ||
/// Files to extract basic information from and include in the list. | ||
/// </summary> | ||
[Required] | ||
public ITaskItem[] Files { get; set; } | ||
|
||
[Required] | ||
public string TargetFile { get; set; } | ||
|
||
/// <summary> | ||
/// Extra attributes to place on the root node. | ||
/// | ||
/// %(Identity): Attribute name. | ||
/// %(Value): Attribute value. | ||
/// </summary> | ||
public ITaskItem[] RootAttributes { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
XAttribute[] rootAttributes = RootAttributes | ||
?.Select(item => new XAttribute(item.ItemSpec, item.GetMetadata("Value"))) | ||
.ToArray(); | ||
|
||
var frameworkManifest = new XElement("FileList", rootAttributes); | ||
|
||
foreach (var f in Files | ||
.Where(item => | ||
item.GetMetadata("TargetPath")?.StartsWith("data/") == true && | ||
item.ItemSpec.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) | ||
.Select(item => new | ||
{ | ||
Item = item, | ||
AssemblyName = FileUtilities.GetAssemblyName(item.ItemSpec), | ||
FileVersion = FileUtilities.GetFileVersion(item.ItemSpec) | ||
}) | ||
.Where(f => f.AssemblyName != null) | ||
.OrderBy(f => f.Item.ItemSpec, StringComparer.OrdinalIgnoreCase)) | ||
{ | ||
byte[] publicKeyToken = f.AssemblyName.GetPublicKeyToken(); | ||
string publicKeyTokenHex; | ||
|
||
if (publicKeyToken != null) | ||
{ | ||
publicKeyTokenHex = BitConverter.ToString(publicKeyToken) | ||
.ToLowerInvariant() | ||
.Replace("-", ""); | ||
} | ||
else | ||
{ | ||
Log.LogError($"No public key token found for assembly {f.Item.ItemSpec}"); | ||
publicKeyTokenHex = ""; | ||
} | ||
|
||
frameworkManifest.Add(new XElement( | ||
"File", | ||
new XAttribute("AssemblyName", f.AssemblyName.Name), | ||
new XAttribute("PublicKeyToken", publicKeyTokenHex), | ||
new XAttribute("AssemblyVersion", f.AssemblyName.Version), | ||
new XAttribute("FileVersion", f.FileVersion))); | ||
} | ||
|
||
Directory.CreateDirectory(Path.GetDirectoryName(TargetFile)); | ||
File.WriteAllText(TargetFile, frameworkManifest.ToString()); | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters