Skip to content

Commit 0e12274

Browse files
authored
Flatten the dependency graph of Microsoft.AspNetCore.App (#4061)
This changes the way Microsoft.AspNetCore.App works to follow patterns set by Microsoft.NETCore.App. Instead of being a metapackage with dozens of dependencies, this package has no dependencies. It uses RID-splitting to deliver standalone assets for self-contained deployments. Changes: * Implements RID-split packages for Microsoft.AspNetCore.App. * Update shared fx deps.json generation to only include entries for the RID-specific metapackages * Include platform-specific packages in publish output * Remove all nuspec dependencies of Microsoft.AspNetCore.App and collect all references into the package.
1 parent 6586538 commit 0e12274

40 files changed

+326
-467
lines changed

.azure/pipelines/jobs/default-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- job: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
6464
displayName: ${{ coalesce(parameters.jobDisplayName, parameters.agentOs) }}
6565
dependsOn: ${{ parameters.dependsOn }}
66-
timeoutInMinutes: 90
66+
timeoutInMinutes: 120
6767
workspace:
6868
clean: all
6969
strategy:

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
<Import Project="eng\targets\RuntimeIdentifiers.props" />
9898
<Import Project="eng\targets\Cpp.Common.props" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
9999
<Import Project="eng\targets\CSharp.Common.props" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
100-
<Import Project="eng\targets\SharedFx.Common.props" Condition="'$(MSBuildProjectExtension)' == '.shfxproj'" />
101100
<Import Project="eng\targets\Wix.Common.props" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />
102101

103102
</Project>

Directory.Build.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@
5454

5555
<Import Project="eng\targets\Cpp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
5656
<Import Project="eng\targets\CSharp.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.csproj'" />
57-
<Import Project="eng\targets\SharedFx.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.shfxproj'" />
5857
<Import Project="eng\targets\Wix.Common.targets" Condition="'$(MSBuildProjectExtension)' == '.wixproj'" />
5958
</Project>

build/Publish.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
Value="$(PackageVersion)" />
5959
</Target>
6060

61-
<Target Name="GetFilesToPublish" DependsOnTargets="GetArtifactInfo;GeneratePublishFiles">
61+
<Target Name="GetFilesToPublish" DependsOnTargets="GetAllRidPackages;GetArtifactInfo;GeneratePublishFiles">
6262
<PropertyGroup>
6363
<BlobBasePath>aspnetcore/Runtime/$(PackageVersion)/</BlobBasePath>
6464
<NpmBlobBasePath>aspnetcore/npm/</NpmBlobBasePath>
@@ -175,6 +175,11 @@
175175
<Output TaskParameter="JoinResult" ItemName="_PackageArtifactInfoWithCategory" />
176176
</RepoTasks.JoinItems>
177177

178+
<ItemGroup>
179+
<_RidSpecificPackages Include="$(SupportedRuntimeIdentifiers)" Exclude="$(SharedFxRid)" />
180+
<PackageToPublish Include="$(DependencyPackagesDir)runtime.%(_RidSpecificPackages.Identity).Microsoft.AspNetCore.App.$(SharedFxVersion).nupkg" Category="ship" />
181+
</ItemGroup>
182+
178183
<ItemGroup>
179184
<PackageToPublish Include="%(_PackageArtifactInfoWithCategory.ArtifactPath)" Category="%(_PackageArtifactInfoWithCategory.Category)" />
180185
<PackageToPublish Include="%(_PackageArtifactInfo.ArtifactPath)" Category="%(_PackageArtifactInfo.Category)" Condition="'%(_PackageArtifactInfo.Category)' != ''" />

build/SharedFx.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<UnitTestFxProject>$(RepositoryRoot)src\Framework\Framework.UnitTests\Framework.UnitTests.csproj</UnitTestFxProject>
3+
<UnitTestFxProject>$(RepositoryRoot)src\Framework\test\Microsoft.AspNetCore.App.UnitTests.csproj</UnitTestFxProject>
44
<UnitTestFxProject>$([MSBuild]::NormalizePath($(UnitTestFxProject)))</UnitTestFxProject>
55
<CodeSignDependsOn Condition="'$(_ProjectsOnly)' != 'true'">$(CodeSignDependsOn);GetSharedFxFilesToSign</CodeSignDependsOn>
66
<BuildSharedFxDependsOn>_BuildSharedFxProjects;TestSharedFx</BuildSharedFxDependsOn>

build/artifacts.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageArtifact Include="Microsoft.AspNet.Identity.AspNetCoreCompat" Category="noship" />
2424
<PackageArtifact Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Category="noship" />
2525
<PackageArtifact Include="Microsoft.AspNetCore.App" Category="ship" />
26-
<PackageArtifact Include="runtime.$(SharedFxRid).Microsoft.AspNetCore.App" Category="noship" />
26+
<PackageArtifact Include="runtime.$(SharedFxRid).Microsoft.AspNetCore.App" Category="ship" />
2727
<PackageArtifact Include="Microsoft.AspNetCore.Antiforgery" Category="ship" />
2828
<PackageArtifact Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Category="ship" />
2929
<PackageArtifact Include="Microsoft.AspNetCore.AspNetCoreModule" Category="noship" Condition=" '$(OS)' == 'Windows_NT' " />

build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142

143143
<CastleCorePackageVersion>4.2.1</CastleCorePackageVersion>
144144
<DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion>2.2.0-preview1-03124-01</DevDependency_MicrosoftDotNetBuildTasksFeedPackageVersion>
145-
<DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>2.0.0</DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>
145+
<DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>2.1.0</DevDependency_MicrosoftExtensionsDependencyModelPackageVersion>
146146
<DevDependency_WindowsAzureStoragePackageVersion>8.7.0</DevDependency_WindowsAzureStoragePackageVersion>
147147
<FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion>
148148
<IdentityServer4PackageVersion>2.3.0-preview1-update2</IdentityServer4PackageVersion>
Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3-
// Sourced from https://github.com/dotnet/core-setup/tree/be8d8e3486b2bf598ed69d39b1629a24caaba45e/tools-local/tasks, needs to be kept in sync
43

54
using System;
65
using System.Collections.Generic;
76
using System.IO;
87
using System.Linq;
9-
using System.Security.Cryptography;
108
using Microsoft.Build.Framework;
119
using Microsoft.Build.Utilities;
1210
using Microsoft.Extensions.DependencyModel;
@@ -28,21 +26,22 @@ public class ProcessSharedFrameworkDeps : Task
2826
public string OutputPath { get; set; }
2927

3028
[Required]
31-
public string FrameworkName { get; set; }
29+
public string TargetFramework { get; set; }
3230

33-
// When generating the .deps.json file, these files are used to replace "project" libraries with "packages".
34-
public ITaskItem[] ResolvedPackageProjectReferences { get; set; }
31+
[Required]
32+
public string FrameworkName { get; set; }
3533

36-
public string[] PackagesToRemove { get; set; }
34+
[Required]
35+
public string FrameworkVersion { get; set; }
3736

3837
[Required]
39-
public string Runtime { get; set; }
38+
public string BaseRuntimeIdentifier { get; set; }
4039

4140
public override bool Execute()
4241
{
4342
ExecuteCore();
4443

45-
return true;
44+
return !Log.HasLoggedErrors;
4645
}
4746

4847
private void ExecuteCore()
@@ -61,23 +60,69 @@ private void ExecuteCore()
6160

6261
var manager = new RuntimeGraphManager();
6362
var graph = manager.Collect(lockFile);
64-
var expandedGraph = manager.Expand(graph, Runtime);
65-
66-
// Remove the runtime entry for the project which generates the original deps.json. For example, there is no Microsoft.AspNetCore.App.dll.
67-
var trimmedRuntimeLibraries = RuntimeReference.RemoveSharedFxRuntimeEntry(context.RuntimeLibraries, FrameworkName);
63+
var expandedGraph = manager.Expand(graph, BaseRuntimeIdentifier);
6864

69-
trimmedRuntimeLibraries = ResolveProjectsAsPackages(ResolvedPackageProjectReferences, trimmedRuntimeLibraries);
65+
var runtimeFiles = new List<RuntimeFile>();
66+
var nativeFiles = new List<RuntimeFile>();
67+
var resourceAssemblies = new List<ResourceAssembly>();
7068

71-
if (PackagesToRemove != null && PackagesToRemove.Any())
69+
foreach (var library in context.RuntimeLibraries)
7270
{
73-
trimmedRuntimeLibraries = RuntimeReference.RemoveReferences(trimmedRuntimeLibraries, PackagesToRemove);
71+
foreach (var file in library.RuntimeAssemblyGroups.SelectMany(g => g.RuntimeFiles))
72+
{
73+
var path = $"runtimes/{context.Target.Runtime}/lib/{TargetFramework}/{Path.GetFileName(file.Path)}";
74+
runtimeFiles.Add(
75+
new RuntimeFile(
76+
path,
77+
file.AssemblyVersion,
78+
file.FileVersion));
79+
}
80+
81+
foreach (var file in library.NativeLibraryGroups.SelectMany(g => g.RuntimeFiles))
82+
{
83+
var path = $"runtimes/{context.Target.Runtime}/native/{Path.GetFileName(file.Path)}";
84+
nativeFiles.Add(
85+
new RuntimeFile(
86+
path,
87+
file.AssemblyVersion,
88+
file.FileVersion));
89+
}
90+
91+
resourceAssemblies.AddRange(
92+
library.ResourceAssemblies);
7493
}
7594

95+
var runtimePackageName = $"runtime.{context.Target.Runtime}.{FrameworkName}";
96+
97+
var runtimeLibrary = new RuntimeLibrary("package",
98+
runtimePackageName,
99+
FrameworkVersion,
100+
string.Empty,
101+
new[] { new RuntimeAssetGroup(string.Empty, runtimeFiles) },
102+
new[] { new RuntimeAssetGroup(string.Empty, nativeFiles) },
103+
resourceAssemblies,
104+
Array.Empty<Dependency>(),
105+
hashPath: null,
106+
path: $"{runtimePackageName.ToLowerInvariant()}/{FrameworkVersion}",
107+
serviceable: true);
108+
109+
var targetingPackLibrary = new RuntimeLibrary("package",
110+
FrameworkName,
111+
FrameworkVersion,
112+
string.Empty,
113+
Array.Empty<RuntimeAssetGroup>(),
114+
Array.Empty<RuntimeAssetGroup>(),
115+
resourceAssemblies,
116+
new[] { new Dependency(runtimeLibrary.Name, runtimeLibrary.Version) },
117+
hashPath: null,
118+
path: $"{FrameworkName.ToLowerInvariant()}/{FrameworkVersion}",
119+
serviceable: true);
120+
76121
context = new DependencyContext(
77122
context.Target,
78123
CompilationOptions.Default,
79124
Array.Empty<CompilationLibrary>(),
80-
trimmedRuntimeLibraries,
125+
new[] { targetingPackLibrary, runtimeLibrary },
81126
expandedGraph
82127
);
83128

@@ -86,43 +131,5 @@ private void ExecuteCore()
86131
new DependencyContextWriter().Write(context, depsStream);
87132
}
88133
}
89-
90-
private IEnumerable<RuntimeLibrary> ResolveProjectsAsPackages(ITaskItem[] resolvedProjects, IEnumerable<RuntimeLibrary> compilationLibraries)
91-
{
92-
var projects = resolvedProjects.ToDictionary(k => k.GetMetadata("PackageId"), k => k, StringComparer.OrdinalIgnoreCase);
93-
94-
foreach (var library in compilationLibraries)
95-
{
96-
if (projects.TryGetValue(library.Name, out var project))
97-
{
98-
Log.LogMessage("Replacing the library entry for {0}", library.Name);
99-
100-
var packagePath = project.ItemSpec;
101-
var packageId = library.Name;
102-
var version = library.Version;
103-
string packageHash;
104-
using (var sha512 = SHA512.Create())
105-
{
106-
packageHash = "sha512-" + sha512.ComputeHashAsBase64(File.OpenRead(packagePath), leaveStreamOpen: false);
107-
}
108-
109-
yield return new RuntimeLibrary("package",
110-
library.Name,
111-
library.Version,
112-
packageHash,
113-
library.RuntimeAssemblyGroups,
114-
library.NativeLibraryGroups,
115-
library.ResourceAssemblies,
116-
library.Dependencies,
117-
serviceable: true,
118-
path: $"{library.Name}/{library.Version}".ToLowerInvariant(),
119-
hashPath: $"{library.Name}.{library.Version}.nupkg.sha512".ToLowerInvariant());
120-
}
121-
else
122-
{
123-
yield return library;
124-
}
125-
}
126-
}
127134
}
128135
}

build/tasks/RepoTasks.tasks

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<UsingTask TaskName="RepoTasks.JoinItems" AssemblyFile="$(_RepoTaskAssembly)" />
1212
<UsingTask TaskName="RepoTasks.OrderBy" AssemblyFile="$(_RepoTaskAssembly)" />
1313
<UsingTask TaskName="RepoTasks.ProcessSharedFrameworkDeps" AssemblyFile="$(_RepoTaskAssembly)" />
14-
<UsingTask TaskName="RepoTasks.ResolveVersionRange" AssemblyFile="$(_RepoTaskAssembly)" />
1514
<UsingTask TaskName="RepoTasks.PublishToAzureBlob" AssemblyFile="$(_RepoTaskAssembly)" />
1615

1716
<!-- tools from dotnet-buildtools -->

build/tasks/ResolveVersionRange.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.

build/tasks/Utilities/RuntimeGraphManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.IO;
88
using System.Linq;
99
using Microsoft.Extensions.DependencyModel;
10-
using NuGet.Frameworks;
1110
using NuGet.Packaging;
1211
using NuGet.ProjectModel;
1312
using NuGet.RuntimeModel;
@@ -63,4 +62,4 @@ private IEnumerable<string> FindImporters(RuntimeGraph runtimeGraph, string runt
6362
}
6463
}
6564
}
66-
}
65+
}

0 commit comments

Comments
 (0)