|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
4 | 4 | using System.Diagnostics; |
| 5 | +using System.Reflection; |
5 | 6 | using System.Runtime.InteropServices; |
6 | 7 | using Aspire.Cli.Configuration; |
7 | 8 | using Microsoft.Extensions.Configuration; |
@@ -143,15 +144,22 @@ public async Task InstallAsync(CancellationToken cancellationToken = default) |
143 | 144 | Directory.CreateDirectory(sdksDirectory); |
144 | 145 |
|
145 | 146 | // Determine which install script to use based on the platform |
146 | | - var (scriptUrl, scriptFileName, scriptRunner) = GetInstallScriptInfo(); |
| 147 | + var (resourceName, scriptFileName, scriptRunner) = GetInstallScriptInfo(); |
147 | 148 |
|
148 | | - // Download the install script |
| 149 | + // Extract the install script from embedded resources |
149 | 150 | var scriptPath = Path.Combine(sdksDirectory, scriptFileName); |
150 | | - using (var httpClient = new HttpClient()) |
| 151 | + var assembly = Assembly.GetExecutingAssembly(); |
| 152 | + using (var resourceStream = assembly.GetManifestResourceStream(resourceName)) |
151 | 153 | { |
152 | | - httpClient.Timeout = TimeSpan.FromMinutes(5); |
153 | | - var scriptContent = await httpClient.GetStringAsync(scriptUrl, cancellationToken); |
154 | | - await File.WriteAllTextAsync(scriptPath, scriptContent, cancellationToken); |
| 154 | + if (resourceStream == null) |
| 155 | + { |
| 156 | + throw new InvalidOperationException($"Could not find embedded resource: {resourceName}"); |
| 157 | + } |
| 158 | + |
| 159 | + using (var fileStream = File.Create(scriptPath)) |
| 160 | + { |
| 161 | + await resourceStream.CopyToAsync(fileStream, cancellationToken); |
| 162 | + } |
155 | 163 | } |
156 | 164 |
|
157 | 165 | // Make the script executable on Unix-like systems |
@@ -298,23 +306,23 @@ private string GetSdksDirectory() |
298 | 306 | /// <summary> |
299 | 307 | /// Gets the install script information based on the current platform. |
300 | 308 | /// </summary> |
301 | | - /// <returns>A tuple containing the script URL, script file name, and script runner command.</returns> |
302 | | - private static (string ScriptUrl, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo() |
| 309 | + /// <returns>A tuple containing the embedded resource name, script file name, and script runner command.</returns> |
| 310 | + private static (string ResourceName, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo() |
303 | 311 | { |
304 | 312 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
305 | 313 | { |
306 | 314 | // Try pwsh first (PowerShell Core), then fall back to powershell (Windows PowerShell) |
307 | 315 | var powerShellExecutable = GetAvailablePowerShell(); |
308 | 316 | return ( |
309 | | - "https://dot.net/v1/dotnet-install.ps1", |
| 317 | + "Aspire.Cli.Resources.dotnet-install.ps1", |
310 | 318 | "dotnet-install.ps1", |
311 | 319 | powerShellExecutable |
312 | 320 | ); |
313 | 321 | } |
314 | 322 | else |
315 | 323 | { |
316 | 324 | return ( |
317 | | - "https://dot.net/v1/dotnet-install.sh", |
| 325 | + "Aspire.Cli.Resources.dotnet-install.sh", |
318 | 326 | "dotnet-install.sh", |
319 | 327 | "bash" |
320 | 328 | ); |
|
0 commit comments