Skip to content

Commit 5079006

Browse files
authored
Add file manifest for runtime and targeting pack (#11235)
1 parent a9a9298 commit 5079006

File tree

9 files changed

+182
-25
lines changed

9 files changed

+182
-25
lines changed

Directory.Build.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
<SharedFxName>Microsoft.AspNetCore.App</SharedFxName>
7171
<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>
7272

73+
<NETCoreAppFrameworkIdentifier>.NETCoreApp</NETCoreAppFrameworkIdentifier>
74+
<NETCoreAppFramework>netcoreapp$(AspNetCoreMajorMinorVersion)</NETCoreAppFramework>
75+
<AspNetCoreAppFrameworkBrandName>ASP.NET Core $(AspNetCoreMajorMinorVersion)</AspNetCoreAppFrameworkBrandName>
76+
7377
<TargetingPackName>Microsoft.AspNetCore.App.Ref</TargetingPackName>
7478
<RuntimeInstallerBaseName>aspnetcore-runtime</RuntimeInstallerBaseName>
7579
<TargetingPackInstallerBaseName>aspnetcore-targeting-pack</TargetingPackInstallerBaseName>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Xml.Linq;
10+
using Microsoft.Build.Framework;
11+
using Microsoft.Build.Utilities;
12+
13+
namespace RepoTasks
14+
{
15+
public class CreateFrameworkListFile : Task
16+
{
17+
/// <summary>
18+
/// Files to extract basic information from and include in the list.
19+
/// </summary>
20+
[Required]
21+
public ITaskItem[] Files { get; set; }
22+
23+
[Required]
24+
public string TargetFile { get; set; }
25+
26+
/// <summary>
27+
/// Extra attributes to place on the root node.
28+
///
29+
/// %(Identity): Attribute name.
30+
/// %(Value): Attribute value.
31+
/// </summary>
32+
public ITaskItem[] RootAttributes { get; set; }
33+
34+
public override bool Execute()
35+
{
36+
XAttribute[] rootAttributes = RootAttributes
37+
?.Select(item => new XAttribute(item.ItemSpec, item.GetMetadata("Value")))
38+
.ToArray();
39+
40+
var frameworkManifest = new XElement("FileList", rootAttributes);
41+
42+
var usedFileProfiles = new HashSet<string>();
43+
44+
foreach (var f in Files
45+
.Select(item => new
46+
{
47+
Item = item,
48+
Filename = Path.GetFileName(item.ItemSpec),
49+
TargetPath = item.GetMetadata("TargetPath"),
50+
AssemblyName = FileUtilities.GetAssemblyName(item.ItemSpec),
51+
FileVersion = FileUtilities.GetFileVersion(item.ItemSpec),
52+
IsNative = item.GetMetadata("IsNativeImage") == "true",
53+
IsSymbolFile = item.GetMetadata("IsSymbolFile") == "true"
54+
})
55+
.Where(f =>
56+
!f.IsSymbolFile &&
57+
(f.Filename.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || f.IsNative))
58+
.OrderBy(f => f.TargetPath, StringComparer.Ordinal)
59+
.ThenBy(f => f.Filename, StringComparer.Ordinal))
60+
{
61+
var element = new XElement(
62+
"File",
63+
new XAttribute("Type", f.IsNative ? "Native" : "Managed"),
64+
new XAttribute(
65+
"Path",
66+
Path.Combine(f.TargetPath, f.Filename).Replace('\\', '/')));
67+
68+
if (f.AssemblyName != null)
69+
{
70+
byte[] publicKeyToken = f.AssemblyName.GetPublicKeyToken();
71+
string publicKeyTokenHex;
72+
73+
if (publicKeyToken != null)
74+
{
75+
publicKeyTokenHex = BitConverter.ToString(publicKeyToken)
76+
.ToLowerInvariant()
77+
.Replace("-", "");
78+
}
79+
else
80+
{
81+
Log.LogError($"No public key token found for assembly {f.Item.ItemSpec}");
82+
publicKeyTokenHex = "";
83+
}
84+
85+
element.Add(
86+
new XAttribute("AssemblyName", f.AssemblyName.Name),
87+
new XAttribute("PublicKeyToken", publicKeyTokenHex),
88+
new XAttribute("AssemblyVersion", f.AssemblyName.Version));
89+
}
90+
else if (!f.IsNative)
91+
{
92+
// This file isn't managed and isn't native. Leave it off the list.
93+
continue;
94+
}
95+
96+
element.Add(new XAttribute("FileVersion", f.FileVersion));
97+
98+
frameworkManifest.Add(element);
99+
}
100+
101+
Directory.CreateDirectory(Path.GetDirectoryName(TargetFile));
102+
File.WriteAllText(TargetFile, frameworkManifest.ToString());
103+
104+
return !Log.HasLoggedErrors;
105+
}
106+
}
107+
}

eng/tools/RepoTasks/FileUtilities.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,42 @@
77
using System.IO;
88
using System.Reflection;
99

10-
namespace Microsoft.DotNet.Build.Tasks
10+
namespace RepoTasks
1111
{
12-
internal static class FileUtilities
12+
internal static partial class FileUtilities
1313
{
14+
private static readonly HashSet<string> s_assemblyExtensions = new HashSet<string>(
15+
new[] { ".dll", ".exe", ".winmd" },
16+
StringComparer.OrdinalIgnoreCase);
17+
1418
public static Version GetFileVersion(string sourcePath)
1519
{
1620
var fvi = FileVersionInfo.GetVersionInfo(sourcePath);
1721

18-
return fvi != null
19-
? new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart)
20-
: null;
21-
}
22-
23-
private static readonly HashSet<string> _assemblyExtensions = new HashSet<string>(new[] { ".dll", ".exe", ".winmd" }, StringComparer.OrdinalIgnoreCase);
24-
25-
public static Version TryGetAssemblyVersion(string sourcePath)
26-
{
27-
var extension = Path.GetExtension(sourcePath);
22+
if (fvi != null)
23+
{
24+
return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart);
25+
}
2826

29-
return _assemblyExtensions.Contains(extension)
30-
? GetAssemblyVersion(sourcePath)
31-
: null;
27+
return null;
3228
}
3329

34-
private static Version GetAssemblyVersion(string sourcePath)
30+
public static AssemblyName GetAssemblyName(string path)
3531
{
32+
if (!s_assemblyExtensions.Contains(Path.GetExtension(path)))
33+
{
34+
return null;
35+
}
36+
3637
try
3738
{
38-
return AssemblyName.GetAssemblyName(sourcePath)?.Version;
39+
return AssemblyName.GetAssemblyName(path);
3940
}
4041
catch (BadImageFormatException)
4142
{
42-
// If an .dll file cannot be read, it may be a native .dll which would not have an assembly version.
43+
// Not a valid assembly.
4344
return null;
4445
}
4546
}
4647
}
47-
}
48+
}

eng/tools/RepoTasks/GenerateSharedFrameworkDepsFile.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Text;
1111
using Microsoft.Build.Framework;
1212
using Microsoft.Build.Utilities;
13-
using Microsoft.DotNet.Build.Tasks;
1413
using Microsoft.Extensions.DependencyModel;
1514

1615
namespace RepoTasks
@@ -61,7 +60,7 @@ private void ExecuteCore()
6160
var filePath = reference.ItemSpec;
6261
var fileName = Path.GetFileName(filePath);
6362
var fileVersion = FileUtilities.GetFileVersion(filePath)?.ToString() ?? string.Empty;
64-
var assemblyVersion = FileUtilities.TryGetAssemblyVersion(filePath);
63+
var assemblyVersion = FileUtilities.GetAssemblyName(filePath)?.Version;
6564
if (assemblyVersion == null)
6665
{
6766
var nativeFile = new RuntimeFile(fileName, null, fileVersion);

eng/tools/RepoTasks/RepoTasks.tasks

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<UsingTask TaskName="RepoTasks.GenerateGuid" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" />
99
<UsingTask TaskName="RepoTasks.GetMsiProperty" AssemblyFile="$(_RepoTaskAssembly)" Condition="'$(MSBuildRuntimeType)' != 'core'" />
1010
<UsingTask TaskName="RepoTasks.GenerateSharedFrameworkDepsFile" AssemblyFile="$(_RepoTaskAssembly)" />
11+
<UsingTask TaskName="RepoTasks.CreateFrameworkListFile" AssemblyFile="$(_RepoTaskAssembly)" />
1112
<UsingTask TaskName="RepoTasks.RemoveSharedFrameworkDependencies" AssemblyFile="$(_RepoTaskAssembly)" />
1213
</Project>

src/Framework/Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88
<PlatformManifestOutputPath>$(ArtifactsObjDir)$(PlatformManifestFileName)</PlatformManifestOutputPath>
99
</PropertyGroup>
1010

11+
<ItemGroup>
12+
<FrameworkListRootAttributes Include="Name" Value="$(AspNetCoreAppFrameworkBrandName)" />
13+
<FrameworkListRootAttributes Include="TargetFrameworkIdentifier" Value="$(NETCoreAppFrameworkIdentifier)" />
14+
<FrameworkListRootAttributes Include="TargetFrameworkVersion" Value="$(AspNetCoreMajorMinorVersion)" />
15+
<FrameworkListRootAttributes Include="FrameworkName" Value="$(SharedFxName)" />
16+
</ItemGroup>
17+
1118
</Project>

src/Framework/build.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
SET RepoRoot=%~dp0..\..
3+
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*

src/Framework/ref/Microsoft.AspNetCore.App.Ref.csproj

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ This package is an internal implementation of the .NET Core SDK and is not meant
3636

3737
<!-- Reference implementation assemblies in addition to ref assemblies to get xml docs -->
3838
<ReferenceImplementationAssemblies>true</ReferenceImplementationAssemblies>
39+
40+
<!-- Platform manifest data -->
41+
<FrameworkListFileName>FrameworkList.xml</FrameworkListFileName>
42+
<FrameworkListOutputPath>$(ArtifactsObjDir)$(FrameworkListFileName)</FrameworkListOutputPath>
3943
</PropertyGroup>
4044

4145
<ItemGroup>
@@ -67,6 +71,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
6771
$(BuildDependsOn);
6872
GeneratePackageConflictManifest;
6973
_ResolveTargetingPackContent;
74+
IncludeFrameworkListFile;
7075
_BatchCopyToLayoutTargetDir;
7176
_InstallTargetingPackIntoLocalDotNet;
7277
_CreateTargetingPackArchive;
@@ -113,8 +118,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant
113118
<RefPackContent Include="@(AspNetCoreReferenceDocXml)" PackagePath="$(RefAssemblyPackagePath)" />
114119
<RefPackContent Include="$(TargetDir)$(PackageConflictManifestFileName)" PackagePath="$(ManifestsPackagePath)" />
115120
<RefPackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" />
116-
117-
<_PackageFiles Include="@(RefPackContent)" />
118121
</ItemGroup>
119122
</Target>
120123

@@ -174,4 +177,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant
174177
<Message Importance="High" Text="$(MSBuildProjectName) -> $(TarArchiveOutputPath)" />
175178
</Target>
176179

180+
<Target Name="IncludeFrameworkListFile"
181+
DependsOnTargets="_ResolveTargetingPackContent"
182+
BeforeTargets="_GetPackageFiles"
183+
Condition="'$(PackageTargetRuntime)' == '' AND '$(ManifestsPackagePath)' != ''">
184+
<RepoTasks.CreateFrameworkListFile
185+
Files="@(RefPackContent)"
186+
TargetFile="$(FrameworkListOutputPath)"
187+
RootAttributes="@(FrameworkListRootAttributes)" />
188+
189+
<ItemGroup>
190+
<RefPackContent Include="$(FrameworkListOutputPath)" PackagePath="$(ManifestsPackagePath)" />
191+
<_PackageFiles Include="@(RefPackContent)" />
192+
</ItemGroup>
193+
</Target>
194+
177195
</Project>

src/Framework/src/Microsoft.AspNetCore.App.Runtime.csproj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ This package is an internal implementation of the .NET Core SDK and is not meant
100100
<RuntimePackageRoot>$([MSBuild]::EnsureTrailingSlash('$(RuntimePackageRoot)'))</RuntimePackageRoot>
101101
<CrossgenToolPath>$([System.IO.Path]::Combine('$(RuntimePackageRoot)', 'tools', '$(CrossgenToolPackagePath)'))</CrossgenToolPath>
102102
<AssetTargetFallback>$(AssetTargetFallback);native,Version=0.0</AssetTargetFallback>
103+
104+
<FrameworkListFileName>RuntimeList.xml</FrameworkListFileName>
105+
<FrameworkListOutputPath>$(ArtifactsObjDir)$(FrameworkListFileName)</FrameworkListOutputPath>
103106
</PropertyGroup>
104107

105108
<ItemGroup>
@@ -154,6 +157,7 @@ This package is an internal implementation of the .NET Core SDK and is not meant
154157
GenerateSharedFxVersionsFiles;
155158
Crossgen;
156159
_ResolveSharedFrameworkContent;
160+
IncludeFrameworkListFile;
157161
_DownloadAndExtractDotNetRuntime;
158162
_BatchCopyToSharedFrameworkLayout;
159163
_BatchCopyToRedistLayout;
@@ -275,8 +279,6 @@ This package is an internal implementation of the .NET Core SDK and is not meant
275279
DependsOnTargets="GenerateSharedFxDepsFile">
276280
<ItemGroup>
277281
<RuntimePackContent Include="$(PlatformManifestOutputPath)" PackagePath="$(ManifestsPackagePath)" />
278-
279-
<_PackageFiles Include="@(RuntimePackContent)" />
280282
</ItemGroup>
281283
</Target>
282284

@@ -448,4 +450,19 @@ This package is an internal implementation of the .NET Core SDK and is not meant
448450
Condition="'$(ArchiveExtension)' == '.tar.gz'" />
449451
</Target>
450452

453+
<Target Name="IncludeFrameworkListFile"
454+
DependsOnTargets="_ResolveSharedFrameworkContent"
455+
BeforeTargets="_GetPackageFiles"
456+
Condition="'$(ManifestsPackagePath)' != ''">
457+
<RepoTasks.CreateFrameworkListFile
458+
Files="@(SharedFxContent)"
459+
TargetFile="$(FrameworkListOutputPath)"
460+
RootAttributes="@(FrameworkListRootAttributes)" />
461+
462+
<ItemGroup>
463+
<RuntimePackContent Include="$(FrameworkListOutputPath)" PackagePath="$(ManifestsPackagePath)" />
464+
<_PackageFiles Include="@(RuntimePackContent)" />
465+
</ItemGroup>
466+
</Target>
467+
451468
</Project>

0 commit comments

Comments
 (0)