Skip to content
代码片段 群组 项目
未验证 提交 50790068 编辑于 作者: Justin Kotalik's avatar Justin Kotalik 提交者: GitHub
浏览文件

Add file manifest for runtime and targeting pack (#11235)

上级 a9a9298d
No related branches found
No related tags found
无相关合并请求
...@@ -70,6 +70,10 @@ ...@@ -70,6 +70,10 @@
<SharedFxName>Microsoft.AspNetCore.App</SharedFxName> <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> <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> <TargetingPackName>Microsoft.AspNetCore.App.Ref</TargetingPackName>
<RuntimeInstallerBaseName>aspnetcore-runtime</RuntimeInstallerBaseName> <RuntimeInstallerBaseName>aspnetcore-runtime</RuntimeInstallerBaseName>
<TargetingPackInstallerBaseName>aspnetcore-targeting-pack</TargetingPackInstallerBaseName> <TargetingPackInstallerBaseName>aspnetcore-targeting-pack</TargetingPackInstallerBaseName>
......
// 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; ...@@ -7,41 +7,42 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection; 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) public static Version GetFileVersion(string sourcePath)
{ {
var fvi = FileVersionInfo.GetVersionInfo(sourcePath); var fvi = FileVersionInfo.GetVersionInfo(sourcePath);
return fvi != null if (fvi != null)
? new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart) {
: null; return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart);
} }
private static readonly HashSet<string> _assemblyExtensions = new HashSet<string>(new[] { ".dll", ".exe", ".winmd" }, StringComparer.OrdinalIgnoreCase);
public static Version TryGetAssemblyVersion(string sourcePath)
{
var extension = Path.GetExtension(sourcePath);
return _assemblyExtensions.Contains(extension) return null;
? GetAssemblyVersion(sourcePath)
: null;
} }
private static Version GetAssemblyVersion(string sourcePath) public static AssemblyName GetAssemblyName(string path)
{ {
if (!s_assemblyExtensions.Contains(Path.GetExtension(path)))
{
return null;
}
try try
{ {
return AssemblyName.GetAssemblyName(sourcePath)?.Version; return AssemblyName.GetAssemblyName(path);
} }
catch (BadImageFormatException) 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; return null;
} }
} }
} }
} }
\ No newline at end of file
...@@ -10,7 +10,6 @@ using System.Reflection; ...@@ -10,7 +10,6 @@ using System.Reflection;
using System.Text; using System.Text;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using Microsoft.DotNet.Build.Tasks;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
namespace RepoTasks namespace RepoTasks
...@@ -61,7 +60,7 @@ namespace RepoTasks ...@@ -61,7 +60,7 @@ namespace RepoTasks
var filePath = reference.ItemSpec; var filePath = reference.ItemSpec;
var fileName = Path.GetFileName(filePath); var fileName = Path.GetFileName(filePath);
var fileVersion = FileUtilities.GetFileVersion(filePath)?.ToString() ?? string.Empty; var fileVersion = FileUtilities.GetFileVersion(filePath)?.ToString() ?? string.Empty;
var assemblyVersion = FileUtilities.TryGetAssemblyVersion(filePath); var assemblyVersion = FileUtilities.GetAssemblyName(filePath)?.Version;
if (assemblyVersion == null) if (assemblyVersion == null)
{ {
var nativeFile = new RuntimeFile(fileName, null, fileVersion); var nativeFile = new RuntimeFile(fileName, null, fileVersion);
......
...@@ -8,5 +8,6 @@ ...@@ -8,5 +8,6 @@
<UsingTask TaskName="RepoTasks.GenerateGuid" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" /> <UsingTask TaskName="RepoTasks.GenerateGuid" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" />
<UsingTask TaskName="RepoTasks.GetMsiProperty" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" /> <UsingTask TaskName="RepoTasks.GetMsiProperty" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" />
<UsingTask TaskName="RepoTasks.GenerateSharedFrameworkDepsFile" AssemblyFile="$(_RepoTaskAssembly)" /> <UsingTask TaskName="RepoTasks.GenerateSharedFrameworkDepsFile" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.CreateFrameworkListFile" AssemblyFile="$(_RepoTaskAssembly)" />
<UsingTask TaskName="RepoTasks.RemoveSharedFrameworkDependencies" AssemblyFile="$(_RepoTaskAssembly)" /> <UsingTask TaskName="RepoTasks.RemoveSharedFrameworkDependencies" AssemblyFile="$(_RepoTaskAssembly)" />
</Project> </Project>
...@@ -8,4 +8,11 @@ ...@@ -8,4 +8,11 @@
<PlatformManifestOutputPath>$(ArtifactsObjDir)$(PlatformManifestFileName)</PlatformManifestOutputPath> <PlatformManifestOutputPath>$(ArtifactsObjDir)$(PlatformManifestFileName)</PlatformManifestOutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<FrameworkListRootAttributes Include="Name" Value="$(AspNetCoreAppFrameworkBrandName)" />
<FrameworkListRootAttributes Include="TargetFrameworkIdentifier" Value="$(NETCoreAppFrameworkIdentifier)" />
<FrameworkListRootAttributes Include="TargetFrameworkVersion" Value="$(AspNetCoreMajorMinorVersion)" />
<FrameworkListRootAttributes Include="FrameworkName" Value="$(SharedFxName)" />
</ItemGroup>
</Project> </Project>
@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 ...@@ -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 --> <!-- Reference implementation assemblies in addition to ref assemblies to get xml docs -->
<ReferenceImplementationAssemblies>true</ReferenceImplementationAssemblies> <ReferenceImplementationAssemblies>true</ReferenceImplementationAssemblies>
<!-- Platform manifest data -->
<FrameworkListFileName>FrameworkList.xml</FrameworkListFileName>
<FrameworkListOutputPath>$(ArtifactsObjDir)$(FrameworkListFileName)</FrameworkListOutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
...@@ -67,6 +71,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -67,6 +71,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
$(BuildDependsOn); $(BuildDependsOn);
GeneratePackageConflictManifest; GeneratePackageConflictManifest;
_ResolveTargetingPackContent; _ResolveTargetingPackContent;
IncludeFrameworkListFile;
_BatchCopyToLayoutTargetDir; _BatchCopyToLayoutTargetDir;
_InstallTargetingPackIntoLocalDotNet; _InstallTargetingPackIntoLocalDotNet;
_CreateTargetingPackArchive; _CreateTargetingPackArchive;
...@@ -113,8 +118,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -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="@(AspNetCoreReferenceDocXml)" PackagePath="$(RefAssemblyPackagePath)" />
<RefPackContent Include="$(TargetDir)$(PackageConflictManifestFileName)" PackagePath="$(ManifestsPackagePath)" /> <RefPackContent Include="$(TargetDir)$(PackageConflictManifestFileName)" PackagePath="$(ManifestsPackagePath)" />
<RefPackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" /> <RefPackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" />
<_PackageFiles Include="@(RefPackContent)" />
</ItemGroup> </ItemGroup>
</Target> </Target>
...@@ -174,4 +177,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -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)" /> <Message Importance="High" Text="$(MSBuildProjectName) -> $(TarArchiveOutputPath)" />
</Target> </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> </Project>
...@@ -100,6 +100,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -100,6 +100,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
<RuntimePackageRoot>$([MSBuild]::EnsureTrailingSlash('$(RuntimePackageRoot)'))</RuntimePackageRoot> <RuntimePackageRoot>$([MSBuild]::EnsureTrailingSlash('$(RuntimePackageRoot)'))</RuntimePackageRoot>
<CrossgenToolPath>$([System.IO.Path]::Combine('$(RuntimePackageRoot)', 'tools', '$(CrossgenToolPackagePath)'))</CrossgenToolPath> <CrossgenToolPath>$([System.IO.Path]::Combine('$(RuntimePackageRoot)', 'tools', '$(CrossgenToolPackagePath)'))</CrossgenToolPath>
<AssetTargetFallback>$(AssetTargetFallback);native,Version=0.0</AssetTargetFallback> <AssetTargetFallback>$(AssetTargetFallback);native,Version=0.0</AssetTargetFallback>
<FrameworkListFileName>RuntimeList.xml</FrameworkListFileName>
<FrameworkListOutputPath>$(ArtifactsObjDir)$(FrameworkListFileName)</FrameworkListOutputPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
...@@ -154,6 +157,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -154,6 +157,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
GenerateSharedFxVersionsFiles; GenerateSharedFxVersionsFiles;
Crossgen; Crossgen;
_ResolveSharedFrameworkContent; _ResolveSharedFrameworkContent;
IncludeFrameworkListFile;
_DownloadAndExtractDotNetRuntime; _DownloadAndExtractDotNetRuntime;
_BatchCopyToSharedFrameworkLayout; _BatchCopyToSharedFrameworkLayout;
_BatchCopyToRedistLayout; _BatchCopyToRedistLayout;
...@@ -275,8 +279,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -275,8 +279,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant
DependsOnTargets="GenerateSharedFxDepsFile"> DependsOnTargets="GenerateSharedFxDepsFile">
<ItemGroup> <ItemGroup>
<RuntimePackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" /> <RuntimePackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" />
<_PackageFiles Include="@(RuntimePackContent)" />
</ItemGroup> </ItemGroup>
</Target> </Target>
...@@ -448,4 +450,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant ...@@ -448,4 +450,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant
Condition="'$(ArchiveExtension)' == '.tar.gz'" /> Condition="'$(ArchiveExtension)' == '.tar.gz'" />
</Target> </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> </Project>
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册