Skip to content

Commit 0295f53

Browse files
authored
Stop shipping packages for assemblies which are shared-framework-only (#4178)
The removes the need to ship packages for assemblies which are part of Microsoft.AspNetCore.App. The implementation of this requires first building packages, and then modifying .nuspec's and categorizing packages as "noship". This will be cleaned up in the future as we continue to refactor the way this repository builds.
1 parent 40ef11c commit 0295f53

8 files changed

+279
-124
lines changed

build/SharedFrameworkOnly.props

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
This lists all assemblies which are part of the Microsoft.AspNetCore.App shared framework
3+
and should not ship as NuGet packages.
4+
-->
5+
<Project>
6+
7+
<Import Project="..\src\Framework\Microsoft.AspNetCore.App.props" />
8+
9+
<ItemGroup>
10+
<!-- Packages to be removed from the shared framework but not done yet. -->
11+
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.JsonPatch" />
12+
13+
<!-- Packages for Razor runtime compilation -->
14+
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.Razor.Language" />
15+
<SharedFrameworkAndPackage Include="Microsoft.CodeAnalysis.Razor" />
16+
17+
<!-- Assemblies required by the SignalR client. -->
18+
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.Http.Features" />
19+
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.SignalR.Common" />
20+
<SharedFrameworkAndPackage Include="Microsoft.AspNetCore.SignalR.Protocols.Json" />
21+
22+
<!-- Assemblies produced by this repo that will move to aspnet/Extensions after repo refactoring is done -->
23+
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" />
24+
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
25+
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Identity.Core" />
26+
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Identity.Stores" />
27+
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Localization.Abstractions" />
28+
<SharedFrameworkAndPackage Include="Microsoft.Extensions.Localization" />
29+
30+
<SharedFrameworkOnlyPackage Include="@(Dependency)" Exclude="@(SharedFrameworkAndPackage)" />
31+
</ItemGroup>
32+
33+
</Project>

build/artifacts.props

Lines changed: 104 additions & 101 deletions
Large diffs are not rendered by default.

build/dependencies.folderbuilds.props

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
<Project>
33
<PropertyGroup>
44
<InternalAspNetCoreSdkPackageVersion Condition="'$(InternalAspNetCoreSdkPackageVersion)' == ''">3.0.0-build-20181114.5</InternalAspNetCoreSdkPackageVersion>
5-
<MicrosoftAspNetCoreAspNetCoreModulePackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreAspNetCoreModulePackageVersion>
6-
<MicrosoftAspNetCoreAuthenticationCorePackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreAuthenticationCorePackageVersion>
7-
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
8-
<MicrosoftAspNetCoreDiagnosticsPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreDiagnosticsPackageVersion>
9-
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
10-
<MicrosoftAspNetCoreHostingPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreHostingPackageVersion>
11-
<MicrosoftAspNetCoreHttpExtensionsPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreHttpExtensionsPackageVersion>
12-
<MicrosoftAspNetCoreHttpOverridesPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreHttpOverridesPackageVersion>
13-
<MicrosoftAspNetCoreHttpPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreHttpPackageVersion>
14-
<MicrosoftAspNetCoreHttpSysSourcesPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreHttpSysSourcesPackageVersion>
15-
<MicrosoftAspNetCoreResponseCompressionPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreResponseCompressionPackageVersion>
16-
<MicrosoftAspNetCoreServerHttpSysPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreServerHttpSysPackageVersion>
17-
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
18-
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.7.0-alpha1-10717</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
19-
<MicrosoftAspNetCoreServerKestrelHttpsPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreServerKestrelHttpsPackageVersion>
20-
<MicrosoftAspNetCoreServerKestrelPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreServerKestrelPackageVersion>
21-
<MicrosoftAspNetCoreStaticFilesPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreStaticFilesPackageVersion>
22-
<MicrosoftAspNetCoreTestHostPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreTestHostPackageVersion>
23-
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>3.0.0-alpha1-10717</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
24-
<MicrosoftExtensionsBuffersMemoryPoolSourcesPackageVersion>3.0.0-alpha1-10717</MicrosoftExtensionsBuffersMemoryPoolSourcesPackageVersion>
25-
<MicrosoftNetHttpHeadersPackageVersion>3.0.0-alpha1-10717</MicrosoftNetHttpHeadersPackageVersion>
5+
<MicrosoftAspNetCoreAspNetCoreModulePackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreAspNetCoreModulePackageVersion>
6+
<MicrosoftAspNetCoreAuthenticationCorePackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreAuthenticationCorePackageVersion>
7+
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
8+
<MicrosoftAspNetCoreDiagnosticsPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreDiagnosticsPackageVersion>
9+
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
10+
<MicrosoftAspNetCoreHostingPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreHostingPackageVersion>
11+
<MicrosoftAspNetCoreHttpExtensionsPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreHttpExtensionsPackageVersion>
12+
<MicrosoftAspNetCoreHttpOverridesPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreHttpOverridesPackageVersion>
13+
<MicrosoftAspNetCoreHttpPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreHttpPackageVersion>
14+
<MicrosoftAspNetCoreHttpSysSourcesPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreHttpSysSourcesPackageVersion>
15+
<MicrosoftAspNetCoreResponseCompressionPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreResponseCompressionPackageVersion>
16+
<MicrosoftAspNetCoreServerHttpSysPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreServerHttpSysPackageVersion>
17+
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
18+
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.7.0-alpha1-10773</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
19+
<MicrosoftAspNetCoreServerKestrelHttpsPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreServerKestrelHttpsPackageVersion>
20+
<MicrosoftAspNetCoreServerKestrelPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreServerKestrelPackageVersion>
21+
<MicrosoftAspNetCoreStaticFilesPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreStaticFilesPackageVersion>
22+
<MicrosoftAspNetCoreTestHostPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreTestHostPackageVersion>
23+
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>3.0.0-alpha1-10773</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
24+
<MicrosoftExtensionsBuffersMemoryPoolSourcesPackageVersion>3.0.0-alpha1-10773</MicrosoftExtensionsBuffersMemoryPoolSourcesPackageVersion>
25+
<MicrosoftNetHttpHeadersPackageVersion>3.0.0-alpha1-10773</MicrosoftNetHttpHeadersPackageVersion>
2626
</PropertyGroup>
2727
</Project>

build/repo.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<Import Project="..\eng\targets\RuntimeIdentifiers.props" />
3+
<Import Project="SharedFrameworkOnly.props" />
34

45
<PropertyGroup>
56
<!-- This repo does not have solutions to build -->

build/repo.targets

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
<CompileDependsOn>$(CompileDependsOn);BuildProjects;PackSharedSources</CompileDependsOn>
2323
<CompileDependsOn Condition="'$(_ProjectsOnly)' != 'true'">$(CompileDependsOn);PackProjects;BuildRepositories;BuildSharedFx</CompileDependsOn>
2424
<PackageDependsOn Condition=" '$(_ProjectsOnly)' == 'true'">$(PackageDependsOn);PackProjects</PackageDependsOn>
25+
<PackageDependsOn Condition=" '$(_ProjectsOnly)' != 'true'">$(PackageDependsOn);RemoveSharedFrameworkOnlyRefsFromNuspec</PackageDependsOn>
2526
<PackageDependsOn Condition="'$(TestOnly)' != 'true'">$(PackageDependsOn);CodeSign</PackageDependsOn>
2627
<TestDependsOn>$(TestDependsOn);TestProjects</TestDependsOn>
2728
<TestDependsOn Condition="'$(_ProjectsOnly)' != 'true'">$(TestDependsOn);_TestRepositories</TestDependsOn>
2829
<GetArtifactInfoDependsOn>$(GetArtifactInfoDependsOn);GetProjectArtifactInfo</GetArtifactInfoDependsOn>
2930
<GetArtifactInfoDependsOn>$(GetArtifactInfoDependsOn);ResolveSharedSourcesPackageInfo</GetArtifactInfoDependsOn>
3031
<GetArtifactInfoDependsOn Condition="'$(_ProjectsOnly)' != 'true'">$(GetArtifactInfoDependsOn);ResolveRepoInfo</GetArtifactInfoDependsOn>
32+
33+
<!-- Package modification must happen before code signing. -->
34+
<CodeSignDependsOn>$(CodeSignDependsOn);RemoveSharedFrameworkOnlyRefsFromNuspec</CodeSignDependsOn>
3135
</PropertyGroup>
3236

3337
<Target Name="PrepareOutputPaths">
@@ -282,7 +286,7 @@
282286
<WriteLinesToFile File="$(RepositoryRoot)artifacts\packages.csv" Lines="PackageId,Version;@(ArtifactInfo->WithMetadataValue('ArtifactType', 'NuGetPackage')->'%(PackageId),%(Version)')" Overwrite="true" />
283287
</Target>
284288

285-
<Target Name="ComputeGraph" DependsOnTargets="GetProjectArtifactInfo;GetFxProjectArtifactInfo;ResolveRepoInfo;GeneratePropsFiles">
289+
<Target Name="ComputeGraph" DependsOnTargets="ResolveSharedSourcesPackageInfo;GetProjectArtifactInfo;GetFxProjectArtifactInfo;ResolveRepoInfo;GeneratePropsFiles">
286290
<ItemGroup>
287291
<_UndeclaredPackageArtifact Include="%(ArtifactInfo.PackageId)" Condition="'%(ArtifactInfo.ArtifactType)' == 'NuGetPackage'" />
288292
<_UndeclaredPackageArtifact Remove="@(PackageArtifact)" />
@@ -299,6 +303,28 @@
299303
<Target Name="VerifyPackageArtifactConfig">
300304
<Error Text="Invalid configuration of %(PackageArtifact.Identity). PackageArtifact must have the 'Category' metadata."
301305
Condition="'%(PackageArtifact.Category)' == '' " />
306+
307+
<ItemGroup>
308+
<ExternalDependencyInSharedFx Include="@(Dependency)" Exclude="@(PackageArtifact)" />
309+
<SharedFrameworkShippingPackage Include="@(SharedFrameworkOnlyPackage)" Exclude="@(SharedFrameworkAndPackage);@(ExternalDependencyInSharedFx);@(PackageArtifact->WithMetadataValue('Category','noship'))" />
310+
</ItemGroup>
311+
312+
<Error Text="Assemblies which ship in the shared framework should not also ship as NuGet packages, unless explicitly allowed. Please update the following to 'noship': %0A - @(SharedFrameworkShippingPackage, '%0A - '). "
313+
Condition=" @(SharedFrameworkShippingPackage->Count()) != 0 " />
314+
</Target>
315+
316+
<!-- This is temporary until we can use FrameworkReference to build our own packages. -->
317+
<Target Name="RemoveSharedFrameworkOnlyRefsFromNuspec">
318+
<ItemGroup>
319+
<_BuildOutput Include="$(BuildDir)%(PackageArtifact.Identity).*.nupkg"
320+
Condition=" '%(PackageArtifact.Category)' == 'ship' " />
321+
322+
<SharedFxPackageRefToHide Include="@(SharedFrameworkOnlyPackage)" Exclude="@(ExternalDependency)" />
323+
</ItemGroup>
324+
325+
<RepoTasks.RemoveSharedFrameworkDependencies Condition="@(_BuildOutput->Count()) != 0"
326+
Files="@(_BuildOutput)"
327+
FrameworkOnlyPackages="@(SharedFxPackageRefToHide)" />
302328
</Target>
303329

304330
<Target Name="VerifyExternalDependencyConfig">
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.IO;
7+
using System.IO.Compression;
8+
using System.Linq;
9+
using Microsoft.Build.Framework;
10+
using Microsoft.Build.Utilities;
11+
using NuGet.Packaging;
12+
using NuGet.Packaging.Core;
13+
14+
namespace RepoTasks
15+
{
16+
// This is temporary until we can use FrameworkReference to build our own packages
17+
public class RemoveSharedFrameworkDependencies : Task
18+
{
19+
[Required]
20+
public ITaskItem[] Files { get; set; }
21+
22+
[Required]
23+
public ITaskItem[] FrameworkOnlyPackages { get; set; }
24+
25+
public override bool Execute()
26+
{
27+
var dependencyToRemove = FrameworkOnlyPackages.Select(p => p.ItemSpec).ToHashSet(StringComparer.OrdinalIgnoreCase);
28+
29+
foreach (var file in Files)
30+
{
31+
FilterDependencies(file.ItemSpec, dependencyToRemove);
32+
}
33+
return !Log.HasLoggedErrors;
34+
}
35+
36+
private void FilterDependencies(string targetPath, ISet<string> dependencyToRemove)
37+
{
38+
var fileName = Path.GetFileName(targetPath);
39+
Log.LogMessage($"Updating {fileName}");
40+
41+
using (var fileStream = File.Open(targetPath, FileMode.Open))
42+
using (var package = new ZipArchive(fileStream, ZipArchiveMode.Update))
43+
using (var packageReader = new PackageArchiveReader(fileStream, leaveStreamOpen: true))
44+
{
45+
var dirty = false;
46+
var nuspecFile = packageReader.GetNuspecFile();
47+
using (var stream = package.OpenFile(nuspecFile))
48+
{
49+
var reader = Manifest.ReadFrom(stream, validateSchema: true);
50+
stream.Position = 0;
51+
var packageBuilder = new PackageBuilder(stream, basePath: null);
52+
var updatedGroups = new List<PackageDependencyGroup>();
53+
54+
foreach (var group in packageBuilder.DependencyGroups)
55+
{
56+
var packages = new List<PackageDependency>();
57+
var updatedGroup = new PackageDependencyGroup(group.TargetFramework, packages);
58+
foreach (var dependency in group.Packages)
59+
{
60+
if (dependencyToRemove.Contains(dependency.Id))
61+
{
62+
dirty = true;
63+
Log.LogMessage($" Remove dependency on '{dependency.Id}'");
64+
continue;
65+
}
66+
67+
packages.Add(dependency);
68+
}
69+
70+
updatedGroups.Add(updatedGroup);
71+
}
72+
73+
if (dirty)
74+
{
75+
packageBuilder.DependencyGroups.Clear();
76+
packageBuilder.DependencyGroups.AddRange(updatedGroups);
77+
78+
var updatedManifest = Manifest.Create(packageBuilder);
79+
stream.Position = 0;
80+
stream.SetLength(0);
81+
updatedManifest.Save(stream);
82+
}
83+
else
84+
{
85+
Log.LogMessage($"No changes made to {fileName}");
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}

build/tasks/RepoTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="$(RepoTasksSdkPath)\Sdk.props" Condition="'$(RepoTasksSdkPath)' != '' "/>
33

44
<PropertyGroup>
5-
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

build/tasks/RepoTasks.tasks

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<UsingTask TaskName="RepoTasks.OrderBy" AssemblyFile="$(_RepoTaskAssembly)" />
1111
<UsingTask TaskName="RepoTasks.GenerateSharedFrameworkMetadataFiles" AssemblyFile="$(_RepoTaskAssembly)" />
1212
<UsingTask TaskName="RepoTasks.PublishToAzureBlob" AssemblyFile="$(_RepoTaskAssembly)" />
13+
<UsingTask TaskName="RepoTasks.RemoveSharedFrameworkDependencies" AssemblyFile="$(_RepoTaskAssembly)" />
1314
</Project>

0 commit comments

Comments
 (0)