4
4
using System ;
5
5
using System . Collections . Generic ;
6
6
using System . IO ;
7
- using System . Linq ;
7
+ using System . Reflection ;
8
8
using System . Text . Json ;
9
9
using Microsoft . AspNetCore . Components ;
10
- using Mono . Cecil ;
11
10
12
11
namespace Microsoft . AspNetCore . Blazor . Build
13
12
{
@@ -16,79 +15,44 @@ internal class BootJsonWriter
16
15
public static void WriteFile (
17
16
string assemblyPath ,
18
17
string [ ] assemblyReferences ,
19
- string [ ] embeddedResourcesSources ,
20
18
bool linkerEnabled ,
21
19
string outputPath )
22
20
{
23
- var embeddedContent = EmbeddedResourcesProcessor . ExtractEmbeddedResources (
24
- embeddedResourcesSources , Path . GetDirectoryName ( outputPath ) ) ;
25
21
var bootJsonText = GetBootJsonContent (
26
- Path . GetFileName ( assemblyPath ) ,
27
- GetAssemblyEntryPoint ( assemblyPath ) ,
22
+ AssemblyName . GetAssemblyName ( assemblyPath ) . Name ,
28
23
assemblyReferences ,
29
- embeddedContent ,
30
24
linkerEnabled ) ;
31
25
var normalizedOutputPath = Path . GetFullPath ( outputPath ) ;
32
26
Console . WriteLine ( "Writing boot data to: " + normalizedOutputPath ) ;
33
27
File . WriteAllText ( normalizedOutputPath , bootJsonText ) ;
34
28
}
35
29
36
- public static string GetBootJsonContent ( string assemblyFileName , string entryPoint , string [ ] assemblyReferences , IEnumerable < EmbeddedResourceInfo > embeddedContent , bool linkerEnabled )
30
+ public static string GetBootJsonContent ( string entryAssembly , string [ ] assemblyReferences , bool linkerEnabled )
37
31
{
38
32
var data = new BootJsonData (
39
- assemblyFileName ,
40
- entryPoint ,
33
+ entryAssembly ,
41
34
assemblyReferences ,
42
- embeddedContent ,
43
35
linkerEnabled ) ;
44
36
return JsonSerializer . Serialize ( data , JsonSerializerOptionsProvider . Options ) ;
45
37
}
46
38
47
- private static string GetAssemblyEntryPoint ( string assemblyPath )
48
- {
49
- using ( var assemblyDefinition = AssemblyDefinition . ReadAssembly ( assemblyPath ) )
50
- {
51
- var entryPoint = assemblyDefinition . EntryPoint ;
52
- if ( entryPoint == null )
53
- {
54
- throw new ArgumentException ( $ "The assembly at { assemblyPath } has no specified entry point.") ;
55
- }
56
-
57
- return $ "{ entryPoint . DeclaringType . FullName } ::{ entryPoint . Name } ";
58
- }
59
- }
60
-
61
39
/// <summary>
62
40
/// Defines the structure of a Blazor boot JSON file
63
41
/// </summary>
64
- class BootJsonData
42
+ readonly struct BootJsonData
65
43
{
66
- public string Main { get ; }
67
- public string EntryPoint { get ; }
44
+ public string EntryAssembly { get ; }
68
45
public IEnumerable < string > AssemblyReferences { get ; }
69
- public IEnumerable < string > CssReferences { get ; }
70
- public IEnumerable < string > JsReferences { get ; }
71
46
public bool LinkerEnabled { get ; }
72
47
73
48
public BootJsonData (
74
- string entrypointAssemblyWithExtension ,
75
- string entryPoint ,
49
+ string entryAssembly ,
76
50
IEnumerable < string > assemblyReferences ,
77
- IEnumerable < EmbeddedResourceInfo > embeddedContent ,
78
51
bool linkerEnabled )
79
52
{
80
- Main = entrypointAssemblyWithExtension ;
81
- EntryPoint = entryPoint ;
53
+ EntryAssembly = entryAssembly ;
82
54
AssemblyReferences = assemblyReferences ;
83
55
LinkerEnabled = linkerEnabled ;
84
-
85
- CssReferences = embeddedContent
86
- . Where ( c => c . Kind == EmbeddedResourceKind . Css )
87
- . Select ( c => c . RelativePath ) ;
88
-
89
- JsReferences = embeddedContent
90
- . Where ( c => c . Kind == EmbeddedResourceKind . JavaScript )
91
- . Select ( c => c . RelativePath ) ;
92
56
}
93
57
}
94
58
}
0 commit comments