| 
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,17 +144,20 @@ 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);  | 
 | 153 | +        if (resourceStream == null)  | 
151 | 154 |         {  | 
152 |  | -            httpClient.Timeout = TimeSpan.FromMinutes(5);  | 
153 |  | -            var scriptContent = await httpClient.GetStringAsync(scriptUrl, cancellationToken);  | 
154 |  | -            await File.WriteAllTextAsync(scriptPath, scriptContent, cancellationToken);  | 
 | 155 | +            throw new InvalidOperationException($"Could not find embedded resource: {resourceName}");  | 
155 | 156 |         }  | 
156 | 157 | 
 
  | 
 | 158 | +        using var fileStream = File.Create(scriptPath);  | 
 | 159 | +        await resourceStream.CopyToAsync(fileStream, cancellationToken);  | 
 | 160 | + | 
157 | 161 |         // Make the script executable on Unix-like systems  | 
158 | 162 |         if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))  | 
159 | 163 |         {  | 
@@ -298,23 +302,23 @@ private string GetSdksDirectory()  | 
298 | 302 |     /// <summary>  | 
299 | 303 |     /// Gets the install script information based on the current platform.  | 
300 | 304 |     /// </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()  | 
 | 305 | +    /// <returns>A tuple containing the embedded resource name, script file name, and script runner command.</returns>  | 
 | 306 | +    private static (string ResourceName, string ScriptFileName, string ScriptRunner) GetInstallScriptInfo()  | 
303 | 307 |     {  | 
304 | 308 |         if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))  | 
305 | 309 |         {  | 
306 | 310 |             // Try pwsh first (PowerShell Core), then fall back to powershell (Windows PowerShell)  | 
307 | 311 |             var powerShellExecutable = GetAvailablePowerShell();  | 
308 | 312 |             return (  | 
309 |  | -                "https://dot.net/v1/dotnet-install.ps1",  | 
 | 313 | +                "Aspire.Cli.Resources.dotnet-install.ps1",  | 
310 | 314 |                 "dotnet-install.ps1",  | 
311 | 315 |                 powerShellExecutable  | 
312 | 316 |             );  | 
313 | 317 |         }  | 
314 | 318 |         else  | 
315 | 319 |         {  | 
316 | 320 |             return (  | 
317 |  | -                "https://dot.net/v1/dotnet-install.sh",  | 
 | 321 | +                "Aspire.Cli.Resources.dotnet-install.sh",  | 
318 | 322 |                 "dotnet-install.sh",  | 
319 | 323 |                 "bash"  | 
320 | 324 |             );  | 
 | 
0 commit comments