@@ -25,23 +25,19 @@ static string GetDotnetPath()
25
25
26
26
static int Main ( string [ ] args )
27
27
{
28
- System . Console . WriteLine ( MuxerPath ) ;
29
28
var sdkDirectory = args . Length > 0 ? args [ 0 ] : Path . GetDirectoryName ( MuxerPath ) ;
30
29
var tempDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "tmp" , Path . GetRandomFileName ( ) ) ;
31
30
var restoreDirectory = Path . Combine ( tempDirectory , ".nuget" ) ;
32
31
33
32
try
34
33
{
35
- var restore = Restore ( tempDirectory , restoreDirectory , out var packs ) ;
34
+ var packs = GetPacks ( sdkDirectory ) ;
35
+ var restore = RestorePacks ( tempDirectory , restoreDirectory , packs ) ;
36
36
if ( restore != 0 )
37
37
{
38
38
return restore ;
39
39
}
40
40
41
- var sourceManifestDirectory = Path . Combine ( restoreDirectory , "microsoft.net.sdk.blazorwebassembly.aot" , ManifestVersion ) ;
42
- var targetManifestDirectory = Path . Combine ( sdkDirectory , "sdk-manifests" , ManifestVersion , "Microsoft.NET.Sdk.BlazorWebAssembly.AOT" ) ;
43
- Move ( sourceManifestDirectory , targetManifestDirectory ) ;
44
-
45
41
foreach ( var ( id , version ) in packs )
46
42
{
47
43
var source = Path . Combine ( restoreDirectory , id . ToLowerInvariant ( ) , version ) ;
@@ -59,7 +55,7 @@ static int Main(string[] args)
59
55
sdkVersionProc . WaitForExit ( ) ;
60
56
var sdkVersion = sdkVersionProc . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
61
57
var sentinelPath = Path . Combine ( sdkDirectory , "sdk" , sdkVersion , "EnableWorkloadResolver.sentinel" ) ;
62
- Console . WriteLine ( $ "Writing sentinel to { sentinelPath } .") ;
58
+ Console . WriteLine ( $ "Enabling Workloads support in dotnet SDK v { sdkVersion } .") ;
63
59
64
60
File . WriteAllBytes ( sentinelPath , Array . Empty < byte > ( ) ) ;
65
61
}
@@ -84,64 +80,17 @@ static void Move(string source, string destination)
84
80
Directory . Move ( source , destination ) ;
85
81
}
86
82
87
- static int Restore ( string tempDirectory , string restoreDirectory , out List < ( string , string ) > packs )
83
+ static List < ( string Id , string Version ) > GetPacks ( string sdkDirectory )
88
84
{
89
- packs = null ;
90
-
91
- var restoreProject = Path . Combine ( tempDirectory , "restore" , "Restore.csproj" ) ;
92
- var restoreProjectDirectory = Directory . CreateDirectory ( Path . GetDirectoryName ( restoreProject ) ) ;
93
-
94
- File . WriteAllText ( Path . Combine ( restoreProjectDirectory . FullName , "Directory.Build.props" ) , "<Project />" ) ;
95
- File . WriteAllText ( Path . Combine ( restoreProjectDirectory . FullName , "Directory.Build.targets" ) , "<Project />" ) ;
96
-
97
- var projectFile = @"
98
- <Project Sdk=""Microsoft.NET.Sdk"">
99
- <PropertyGroup>
100
- <TargetFramework>net6.0</TargetFramework>
101
- </PropertyGroup>
102
- <ItemGroup>
103
- <PackageReference Include=""Microsoft.NET.Sdk.BlazorWebAssembly.AOT"" Version=""6.0.0-*"" />
104
- </ItemGroup>
105
- </Project>
106
- " ;
107
- File . WriteAllText ( restoreProject , projectFile ) ;
108
-
109
- Console . WriteLine ( "Restoring..." ) ;
110
-
111
- var process = Process . Start ( new ProcessStartInfo
112
- {
113
- FileName = MuxerPath ,
114
- ArgumentList = { "restore" , restoreProject } ,
115
- Environment =
116
- {
117
- [ "NUGET_PACKAGES" ] = restoreDirectory ,
118
- } ,
119
- } ) ;
120
- process . WaitForExit ( ) ;
121
- if ( process . ExitCode != 0 )
85
+ var manifestDirectory = Path . Combine ( sdkDirectory , "sdk-manifests" , ManifestVersion , "Microsoft.NET.Workload.BlazorWebAssembly" ) ;
86
+ if ( ! Directory . Exists ( manifestDirectory ) )
122
87
{
123
- Console . Error . WriteLine ( "Unable to restore Microsoft.NET.Sdk.BlazorWebAssembly.AOT workload." ) ;
124
- return 1 ;
88
+ throw new DirectoryNotFoundException ( $ "Cound not find directory { manifestDirectory } . A 6.0-preview3 SDK or newer is required for this tool to function.") ;
125
89
}
126
90
127
- var manifestDirectory = Path . Combine ( restoreDirectory , "microsoft.net.sdk.blazorwebassembly.aot" ) ;
128
- var version = Directory . EnumerateDirectories ( manifestDirectory ) . First ( ) ;
129
-
130
- manifestDirectory = Path . Combine ( manifestDirectory , ManifestVersion ) ;
131
- Directory . Move ( version , manifestDirectory ) ;
132
-
133
91
var manifestPath = Path . Combine ( manifestDirectory , "WorkloadManifest.json" ) ;
134
92
var manifest = JsonSerializer . Deserialize < PackInformation > ( File . ReadAllBytes ( manifestPath ) , new JsonSerializerOptions ( JsonSerializerDefaults . Web ) ) ;
135
-
136
- projectFile = @"
137
- <Project Sdk=""Microsoft.NET.Sdk"">
138
- <PropertyGroup>
139
- <TargetFramework>net6.0</TargetFramework>
140
- <NoWarn>$(NoWarn);NU1213</NoWarn>
141
- </PropertyGroup>
142
- <ItemGroup>
143
- " ;
144
- packs = new List < ( string id , string version ) > ( ) ;
93
+ var packs = new List < ( string , string ) > ( ) ;
145
94
foreach ( var item in manifest . Packs )
146
95
{
147
96
var packageName = item . Key ;
@@ -161,34 +110,56 @@ static int Restore(string tempDirectory, string restoreDirectory, out List<(stri
161
110
}
162
111
else
163
112
{
164
- Console . Error . WriteLine ( "Unsupported platform." ) ;
165
- return 1 ;
113
+ throw new NotSupportedException ( "Unsupported OS platform." ) ;
166
114
}
167
115
}
168
- projectFile += @$ "<PackageReference Include=""{ packageName } "" Version=""{ item . Value . Version } "" />";
169
116
packs . Add ( ( packageName , item . Value . Version ) ) ;
170
117
}
171
118
119
+ return packs ;
120
+ }
121
+
122
+ static int RestorePacks ( string tempDirectory , string restoreDirectory , List < ( string Id , string Version ) > packs )
123
+ {
124
+ var restoreProject = Path . Combine ( tempDirectory , "restore" , "Restore.csproj" ) ;
125
+ var restoreProjectDirectory = Directory . CreateDirectory ( Path . GetDirectoryName ( restoreProject ) ) ;
126
+
127
+ File . WriteAllText ( Path . Combine ( restoreProjectDirectory . FullName , "Directory.Build.props" ) , "<Project />" ) ;
128
+ File . WriteAllText ( Path . Combine ( restoreProjectDirectory . FullName , "Directory.Build.targets" ) , "<Project />" ) ;
129
+
130
+ var projectFile = @"
131
+ <Project Sdk=""Microsoft.NET.Sdk"">
132
+ <PropertyGroup>
133
+ <TargetFramework>net6.0</TargetFramework>
134
+ <NoWarn>$(NoWarn);NU1213</NoWarn>
135
+ </PropertyGroup>
136
+ <ItemGroup>
137
+ " ;
138
+ foreach ( var ( Id , Version ) in packs )
139
+ {
140
+ projectFile += $ "<PackageReference Include=\" { Id } \" Version=\" { Version } \" />";
141
+ }
142
+
172
143
projectFile += @"
173
144
</ItemGroup>
174
145
</Project>
175
146
" ;
176
147
File . WriteAllText ( restoreProject , projectFile ) ;
177
148
178
- process = Process . Start ( new ProcessStartInfo
149
+ var process = Process . Start ( new ProcessStartInfo
179
150
{
180
151
FileName = MuxerPath ,
181
152
ArgumentList = { "restore" , restoreProject } ,
153
+ #if ! DEBUG
182
154
RedirectStandardError = true ,
183
155
RedirectStandardOutput = true ,
156
+ #endif
184
157
Environment =
185
158
{
186
159
[ "NUGET_PACKAGES" ] = restoreDirectory ,
187
160
} ,
188
161
} ) ;
189
162
process . WaitForExit ( ) ;
190
-
191
-
192
163
return 0 ;
193
164
}
194
165
0 commit comments