@@ -25,23 +25,19 @@ static string GetDotnetPath()
2525
2626 static int Main ( string [ ] args )
2727 {
28- System . Console . WriteLine ( MuxerPath ) ;
2928 var sdkDirectory = args . Length > 0 ? args [ 0 ] : Path . GetDirectoryName ( MuxerPath ) ;
3029 var tempDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "tmp" , Path . GetRandomFileName ( ) ) ;
3130 var restoreDirectory = Path . Combine ( tempDirectory , ".nuget" ) ;
3231
3332 try
3433 {
35- var restore = Restore ( tempDirectory , restoreDirectory , out var packs ) ;
34+ var packs = GetPacks ( sdkDirectory ) ;
35+ var restore = RestorePacks ( tempDirectory , restoreDirectory , packs ) ;
3636 if ( restore != 0 )
3737 {
3838 return restore ;
3939 }
4040
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-
4541 foreach ( var ( id , version ) in packs )
4642 {
4743 var source = Path . Combine ( restoreDirectory , id . ToLowerInvariant ( ) , version ) ;
@@ -59,7 +55,7 @@ static int Main(string[] args)
5955 sdkVersionProc . WaitForExit ( ) ;
6056 var sdkVersion = sdkVersionProc . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
6157 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 } .") ;
6359
6460 File . WriteAllBytes ( sentinelPath , Array . Empty < byte > ( ) ) ;
6561 }
@@ -84,64 +80,17 @@ static void Move(string source, string destination)
8480 Directory . Move ( source , destination ) ;
8581 }
8682
87- static int Restore ( string tempDirectory , string restoreDirectory , out List < ( string , string ) > packs )
83+ static List < ( string Id , string Version ) > GetPacks ( string sdkDirectory )
8884 {
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 ) )
12287 {
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.") ;
12589 }
12690
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-
13391 var manifestPath = Path . Combine ( manifestDirectory , "WorkloadManifest.json" ) ;
13492 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 ) > ( ) ;
14594 foreach ( var item in manifest . Packs )
14695 {
14796 var packageName = item . Key ;
@@ -161,34 +110,56 @@ static int Restore(string tempDirectory, string restoreDirectory, out List<(stri
161110 }
162111 else
163112 {
164- Console . Error . WriteLine ( "Unsupported platform." ) ;
165- return 1 ;
113+ throw new NotSupportedException ( "Unsupported OS platform." ) ;
166114 }
167115 }
168- projectFile += @$ "<PackageReference Include=""{ packageName } "" Version=""{ item . Value . Version } "" />";
169116 packs . Add ( ( packageName , item . Value . Version ) ) ;
170117 }
171118
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+
172143 projectFile += @"
173144 </ItemGroup>
174145</Project>
175146" ;
176147 File . WriteAllText ( restoreProject , projectFile ) ;
177148
178- process = Process . Start ( new ProcessStartInfo
149+ var process = Process . Start ( new ProcessStartInfo
179150 {
180151 FileName = MuxerPath ,
181152 ArgumentList = { "restore" , restoreProject } ,
153+ #if ! DEBUG
182154 RedirectStandardError = true ,
183155 RedirectStandardOutput = true ,
156+ #endif
184157 Environment =
185158 {
186159 [ "NUGET_PACKAGES" ] = restoreDirectory ,
187160 } ,
188161 } ) ;
189162 process . WaitForExit ( ) ;
190-
191-
192163 return 0 ;
193164 }
194165
0 commit comments