<SkipValidatePackage>true</SkipValidatePackage>
<!-- Include the platform manifest in the data dir. -->
- <PlatformManifestTargetPath>data/</PlatformManifestTargetPath>
+ <PlatformManifestTargetPath>data/PlatformManifest.txt</PlatformManifestTargetPath>
+ <FrameworkListTargetPath>data/</FrameworkListTargetPath>
<!-- Exclude runtime.json from the package. -->
<IncludeRuntimeJson>false</IncludeRuntimeJson>
<PackProjectDependencies>true</PackProjectDependencies>
</PropertyGroup>
+ <ItemGroup>
+ <FrameworkListRootAttributes Include="Name" Value="$(NETCoreAppFrameworkBrandName)" />
+ <FrameworkListRootAttributes Include="TargetFrameworkIdentifier" Value="$(NETCoreAppFrameworkIdentifier)" />
+ <FrameworkListRootAttributes Include="TargetFrameworkVersion" Value="$(NETCoreAppFrameworkVersion)" />
+ <FrameworkListRootAttributes Include="FrameworkName" Value="$(SharedFrameworkName)" />
+ </ItemGroup>
+
<PropertyGroup Condition="'$(PackageTargetRuntime)' == ''">
<SkipValidatePackage>true</SkipValidatePackage>
<IncludeRuntimeJson>true</IncludeRuntimeJson>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.targets" />
+ <UsingTask TaskName="CreateFrameworkListFile" AssemblyFile="$(LocalBuildToolsTaskDir)core-setup.tasks.dll"/>
<UsingTask TaskName="GenerateFileVersionProps" AssemblyFile="$(LocalBuildToolsTaskDir)core-setup.tasks.dll"/>
<PropertyGroup>
</ItemGroup>
</Target>
+ <Target Name="IncludeFrameworkListFile"
+ BeforeTargets="GetFiles"
+ Condition="'$(PackageTargetRuntime)' == '' AND '$(FrameworkListTargetPath)' != ''">
+ <PropertyGroup>
+ <FrameworkListFile>$(IntermediateOutputPath)FrameworkList.xml</FrameworkListFile>
+ </PropertyGroup>
+
+ <CreateFrameworkListFile
+ Files="@(File)"
+ TargetFile="$(FrameworkListFile)"
+ RootAttributes="@(FrameworkListRootAttributes)" />
+
+ <ItemGroup>
+ <File Include="$(FrameworkListFile)">
+ <TargetPath>$(FrameworkListTargetPath)</TargetPath>
+ </File>
+ </ItemGroup>
+ </Target>
+
</Project>
\ No newline at end of file
--- /dev/null
+// 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;
+ }
+ }
+}
namespace Microsoft.DotNet.Build.Tasks
{
- static partial class FileUtilities
+ internal static partial class FileUtilities
{
+ private static readonly HashSet<string> s_assemblyExtensions = new HashSet<string>(
+ new[] { ".dll", ".exe", ".winmd" },
+ StringComparer.OrdinalIgnoreCase);
+
public static Version GetFileVersion(string sourcePath)
{
var fvi = FileVersionInfo.GetVersionInfo(sourcePath);
return null;
}
- static readonly HashSet<string> s_assemblyExtensions = new HashSet<string>(new[] { ".dll", ".exe", ".winmd" }, StringComparer.OrdinalIgnoreCase);
- public static Version TryGetAssemblyVersion(string sourcePath)
+ public static AssemblyName GetAssemblyName(string path)
{
- var extension = Path.GetExtension(sourcePath);
+ if (!s_assemblyExtensions.Contains(Path.GetExtension(path)))
+ {
+ return null;
+ }
- return s_assemblyExtensions.Contains(extension) ? GetAssemblyVersion(sourcePath) : null;
- }
- private static Version GetAssemblyVersion(string sourcePath)
- {
try
{
- return AssemblyName.GetAssemblyName(sourcePath)?.Version;
+ return AssemblyName.GetAssemblyName(path);
}
catch (BadImageFormatException)
{
+ // Not a valid assembly.
return null;
}
}
{
return new FileVersionData()
{
- AssemblyVersion = FileUtilities.TryGetAssemblyVersion(filePath),
+ AssemblyVersion = FileUtilities.GetAssemblyName(filePath)?.Version,
FileVersion = FileUtilities.GetFileVersion(filePath)
};
}