1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// 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
4
3
5
4
using System ;
6
5
using System . Collections . Generic ;
7
6
using System . IO ;
8
7
using System . Linq ;
9
- using System . Security . Cryptography ;
10
8
using Microsoft . Build . Framework ;
11
9
using Microsoft . Build . Utilities ;
12
10
using Microsoft . Extensions . DependencyModel ;
@@ -28,21 +26,22 @@ public class ProcessSharedFrameworkDeps : Task
28
26
public string OutputPath { get ; set ; }
29
27
30
28
[ Required ]
31
- public string FrameworkName { get ; set ; }
29
+ public string TargetFramework { get ; set ; }
32
30
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 ; }
35
33
36
- public string [ ] PackagesToRemove { get ; set ; }
34
+ [ Required ]
35
+ public string FrameworkVersion { get ; set ; }
37
36
38
37
[ Required ]
39
- public string Runtime { get ; set ; }
38
+ public string BaseRuntimeIdentifier { get ; set ; }
40
39
41
40
public override bool Execute ( )
42
41
{
43
42
ExecuteCore ( ) ;
44
43
45
- return true ;
44
+ return ! Log . HasLoggedErrors ;
46
45
}
47
46
48
47
private void ExecuteCore ( )
@@ -61,23 +60,69 @@ private void ExecuteCore()
61
60
62
61
var manager = new RuntimeGraphManager ( ) ;
63
62
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 ) ;
68
64
69
- trimmedRuntimeLibraries = ResolveProjectsAsPackages ( ResolvedPackageProjectReferences , trimmedRuntimeLibraries ) ;
65
+ var runtimeFiles = new List < RuntimeFile > ( ) ;
66
+ var nativeFiles = new List < RuntimeFile > ( ) ;
67
+ var resourceAssemblies = new List < ResourceAssembly > ( ) ;
70
68
71
- if ( PackagesToRemove != null && PackagesToRemove . Any ( ) )
69
+ foreach ( var library in context . RuntimeLibraries )
72
70
{
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 ) ;
74
93
}
75
94
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
+
76
121
context = new DependencyContext (
77
122
context . Target ,
78
123
CompilationOptions . Default ,
79
124
Array . Empty < CompilationLibrary > ( ) ,
80
- trimmedRuntimeLibraries ,
125
+ new [ ] { targetingPackLibrary , runtimeLibrary } ,
81
126
expandedGraph
82
127
) ;
83
128
@@ -86,43 +131,5 @@ private void ExecuteCore()
86
131
new DependencyContextWriter ( ) . Write ( context , depsStream ) ;
87
132
}
88
133
}
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
- }
127
134
}
128
135
}
0 commit comments