Add file manifest for runtime and targeting pack (#11235)
This commit is contained in:
parent
a9a9298d4f
commit
50790068a8
|
|
@ -70,6 +70,10 @@
|
|||
<SharedFxName>Microsoft.AspNetCore.App</SharedFxName>
|
||||
<SharedFxDescription>Shared Framework for hosting of Microsoft ASP.NET Core applications. It is open source, cross-platform and is supported by Microsoft. We hope you enjoy using it! If you do, please consider joining the active community of developers that are contributing to the project on GitHub ($(RepositoryUrl)). We happily accept issues and PRs.</SharedFxDescription>
|
||||
|
||||
<NETCoreAppFrameworkIdentifier>.NETCoreApp</NETCoreAppFrameworkIdentifier>
|
||||
<NETCoreAppFramework>netcoreapp$(AspNetCoreMajorMinorVersion)</NETCoreAppFramework>
|
||||
<AspNetCoreAppFrameworkBrandName>ASP.NET Core $(AspNetCoreMajorMinorVersion)</AspNetCoreAppFrameworkBrandName>
|
||||
|
||||
<TargetingPackName>Microsoft.AspNetCore.App.Ref</TargetingPackName>
|
||||
<RuntimeInstallerBaseName>aspnetcore-runtime</RuntimeInstallerBaseName>
|
||||
<TargetingPackInstallerBaseName>aspnetcore-targeting-pack</TargetingPackInstallerBaseName>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
namespace RepoTasks
|
||||
{
|
||||
public class CreateFrameworkListFile : Task
|
||||
{
|
||||
/// <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);
|
||||
|
||||
var usedFileProfiles = new HashSet<string>();
|
||||
|
||||
foreach (var f in Files
|
||||
.Select(item => new
|
||||
{
|
||||
Item = item,
|
||||
Filename = Path.GetFileName(item.ItemSpec),
|
||||
TargetPath = item.GetMetadata("TargetPath"),
|
||||
AssemblyName = FileUtilities.GetAssemblyName(item.ItemSpec),
|
||||
FileVersion = FileUtilities.GetFileVersion(item.ItemSpec),
|
||||
IsNative = item.GetMetadata("IsNativeImage") == "true",
|
||||
IsSymbolFile = item.GetMetadata("IsSymbolFile") == "true"
|
||||
})
|
||||
.Where(f =>
|
||||
!f.IsSymbolFile &&
|
||||
(f.Filename.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || f.IsNative))
|
||||
.OrderBy(f => f.TargetPath, StringComparer.Ordinal)
|
||||
.ThenBy(f => f.Filename, StringComparer.Ordinal))
|
||||
{
|
||||
var element = new XElement(
|
||||
"File",
|
||||
new XAttribute("Type", f.IsNative ? "Native" : "Managed"),
|
||||
new XAttribute(
|
||||
"Path",
|
||||
Path.Combine(f.TargetPath, f.Filename).Replace('\\', '/')));
|
||||
|
||||
if (f.AssemblyName != null)
|
||||
{
|
||||
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 = "";
|
||||
}
|
||||
|
||||
element.Add(
|
||||
new XAttribute("AssemblyName", f.AssemblyName.Name),
|
||||
new XAttribute("PublicKeyToken", publicKeyTokenHex),
|
||||
new XAttribute("AssemblyVersion", f.AssemblyName.Version));
|
||||
}
|
||||
else if (!f.IsNative)
|
||||
{
|
||||
// This file isn't managed and isn't native. Leave it off the list.
|
||||
continue;
|
||||
}
|
||||
|
||||
element.Add(new XAttribute("FileVersion", f.FileVersion));
|
||||
|
||||
frameworkManifest.Add(element);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(TargetFile));
|
||||
File.WriteAllText(TargetFile, frameworkManifest.ToString());
|
||||
|
||||
return !Log.HasLoggedErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,41 +7,42 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.DotNet.Build.Tasks
|
||||
namespace RepoTasks
|
||||
{
|
||||
internal static 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 fvi != null
|
||||
? new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart)
|
||||
: null;
|
||||
if (fvi != null)
|
||||
{
|
||||
return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static readonly HashSet<string> _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 _assemblyExtensions.Contains(extension)
|
||||
? GetAssemblyVersion(sourcePath)
|
||||
: null;
|
||||
}
|
||||
|
||||
private static Version GetAssemblyVersion(string sourcePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return AssemblyName.GetAssemblyName(sourcePath)?.Version;
|
||||
return AssemblyName.GetAssemblyName(path);
|
||||
}
|
||||
catch (BadImageFormatException)
|
||||
{
|
||||
// If an .dll file cannot be read, it may be a native .dll which would not have an assembly version.
|
||||
// Not a valid assembly.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ using System.Reflection;
|
|||
using System.Text;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.DotNet.Build.Tasks;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
|
||||
namespace RepoTasks
|
||||
|
|
@ -61,7 +60,7 @@ namespace RepoTasks
|
|||
var filePath = reference.ItemSpec;
|
||||
var fileName = Path.GetFileName(filePath);
|
||||
var fileVersion = FileUtilities.GetFileVersion(filePath)?.ToString() ?? string.Empty;
|
||||
var assemblyVersion = FileUtilities.TryGetAssemblyVersion(filePath);
|
||||
var assemblyVersion = FileUtilities.GetAssemblyName(filePath)?.Version;
|
||||
if (assemblyVersion == null)
|
||||
{
|
||||
var nativeFile = new RuntimeFile(fileName, null, fileVersion);
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@
|
|||
<UsingTask TaskName="RepoTasks.GenerateGuid" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" />
|
||||
<UsingTask TaskName="RepoTasks.GetMsiProperty" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" />
|
||||
<UsingTask TaskName="RepoTasks.GenerateSharedFrameworkDepsFile" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||
<UsingTask TaskName="RepoTasks.CreateFrameworkListFile" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||
<UsingTask TaskName="RepoTasks.RemoveSharedFrameworkDependencies" AssemblyFile="$(_RepoTaskAssembly)" />
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -8,4 +8,11 @@
|
|||
<PlatformManifestOutputPath>$(ArtifactsObjDir)$(PlatformManifestFileName)</PlatformManifestOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkListRootAttributes Include="Name" Value="$(AspNetCoreAppFrameworkBrandName)" />
|
||||
<FrameworkListRootAttributes Include="TargetFrameworkIdentifier" Value="$(NETCoreAppFrameworkIdentifier)" />
|
||||
<FrameworkListRootAttributes Include="TargetFrameworkVersion" Value="$(AspNetCoreMajorMinorVersion)" />
|
||||
<FrameworkListRootAttributes Include="FrameworkName" Value="$(SharedFxName)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
@ECHO OFF
|
||||
SET RepoRoot=%~dp0..\..
|
||||
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*
|
||||
|
|
@ -36,6 +36,10 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
|
||||
<!-- Reference implementation assemblies in addition to ref assemblies to get xml docs -->
|
||||
<ReferenceImplementationAssemblies>true</ReferenceImplementationAssemblies>
|
||||
|
||||
<!-- Platform manifest data -->
|
||||
<FrameworkListFileName>FrameworkList.xml</FrameworkListFileName>
|
||||
<FrameworkListOutputPath>$(ArtifactsObjDir)$(FrameworkListFileName)</FrameworkListOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -67,6 +71,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
$(BuildDependsOn);
|
||||
GeneratePackageConflictManifest;
|
||||
_ResolveTargetingPackContent;
|
||||
IncludeFrameworkListFile;
|
||||
_BatchCopyToLayoutTargetDir;
|
||||
_InstallTargetingPackIntoLocalDotNet;
|
||||
_CreateTargetingPackArchive;
|
||||
|
|
@ -113,8 +118,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
<RefPackContent Include="@(AspNetCoreReferenceDocXml)" PackagePath="$(RefAssemblyPackagePath)" />
|
||||
<RefPackContent Include="$(TargetDir)$(PackageConflictManifestFileName)" PackagePath="$(ManifestsPackagePath)" />
|
||||
<RefPackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" />
|
||||
|
||||
<_PackageFiles Include="@(RefPackContent)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
|
|
@ -174,4 +177,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
<Message Importance="High" Text="$(MSBuildProjectName) -> $(TarArchiveOutputPath)" />
|
||||
</Target>
|
||||
|
||||
<Target Name="IncludeFrameworkListFile"
|
||||
DependsOnTargets="_ResolveTargetingPackContent"
|
||||
BeforeTargets="_GetPackageFiles"
|
||||
Condition="'$(PackageTargetRuntime)' == '' AND '$(ManifestsPackagePath)' != ''">
|
||||
<RepoTasks.CreateFrameworkListFile
|
||||
Files="@(RefPackContent)"
|
||||
TargetFile="$(FrameworkListOutputPath)"
|
||||
RootAttributes="@(FrameworkListRootAttributes)" />
|
||||
|
||||
<ItemGroup>
|
||||
<RefPackContent Include="$(FrameworkListOutputPath)" PackagePath="$(ManifestsPackagePath)" />
|
||||
<_PackageFiles Include="@(RefPackContent)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -100,6 +100,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
<RuntimePackageRoot>$([MSBuild]::EnsureTrailingSlash('$(RuntimePackageRoot)'))</RuntimePackageRoot>
|
||||
<CrossgenToolPath>$([System.IO.Path]::Combine('$(RuntimePackageRoot)', 'tools', '$(CrossgenToolPackagePath)'))</CrossgenToolPath>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);native,Version=0.0</AssetTargetFallback>
|
||||
|
||||
<FrameworkListFileName>RuntimeList.xml</FrameworkListFileName>
|
||||
<FrameworkListOutputPath>$(ArtifactsObjDir)$(FrameworkListFileName)</FrameworkListOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -154,6 +157,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
GenerateSharedFxVersionsFiles;
|
||||
Crossgen;
|
||||
_ResolveSharedFrameworkContent;
|
||||
IncludeFrameworkListFile;
|
||||
_DownloadAndExtractDotNetRuntime;
|
||||
_BatchCopyToSharedFrameworkLayout;
|
||||
_BatchCopyToRedistLayout;
|
||||
|
|
@ -275,8 +279,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
DependsOnTargets="GenerateSharedFxDepsFile">
|
||||
<ItemGroup>
|
||||
<RuntimePackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" />
|
||||
|
||||
<_PackageFiles Include="@(RuntimePackContent)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
|
|
@ -448,4 +450,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant
|
|||
Condition="'$(ArchiveExtension)' == '.tar.gz'" />
|
||||
</Target>
|
||||
|
||||
<Target Name="IncludeFrameworkListFile"
|
||||
DependsOnTargets="_ResolveSharedFrameworkContent"
|
||||
BeforeTargets="_GetPackageFiles"
|
||||
Condition="'$(ManifestsPackagePath)' != ''">
|
||||
<RepoTasks.CreateFrameworkListFile
|
||||
Files="@(SharedFxContent)"
|
||||
TargetFile="$(FrameworkListOutputPath)"
|
||||
RootAttributes="@(FrameworkListRootAttributes)" />
|
||||
|
||||
<ItemGroup>
|
||||
<RuntimePackContent Include="$(FrameworkListOutputPath)" PackagePath="$(ManifestsPackagePath)" />
|
||||
<_PackageFiles Include="@(RuntimePackContent)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in New Issue