Skip to content

Commit aa3c288

Browse files
Copilotmitchdenny
andcommitted
Embed dotnet-install scripts as resources in Aspire CLI
- Add dotnet-install.sh and dotnet-install.ps1 as embedded resources - Update DotNetSdkInstaller to extract scripts from embedded resources instead of downloading - Remove HttpClient download logic - Add test to verify embedded scripts are accessible Co-authored-by: mitchdenny <[email protected]>
1 parent 39078c7 commit aa3c288

File tree

5 files changed

+3516
-10
lines changed

5 files changed

+3516
-10
lines changed

src/Aspire.Cli/Aspire.Cli.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
</Compile>
120120
</ItemGroup>
121121

122+
<ItemGroup>
123+
<EmbeddedResource Include="Resources\dotnet-install.sh" />
124+
<EmbeddedResource Include="Resources\dotnet-install.ps1" />
125+
</ItemGroup>
126+
122127
<ItemGroup>
123128
<EmbeddedResource Update="Resources\ExecCommandStrings.resx">
124129
<Generator>ResXFileCodeGenerator</Generator>

src/Aspire.Cli/DotNet/DotNetSdkInstaller.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Diagnostics;
5+
using System.Reflection;
56
using System.Runtime.InteropServices;
67
using Aspire.Cli.Configuration;
78
using Microsoft.Extensions.Configuration;
@@ -143,15 +144,22 @@ public async Task InstallAsync(CancellationToken cancellationToken = default)
143144
Directory.CreateDirectory(sdksDirectory);
144145

145146
// Determine which install script to use based on the platform
146-
var (scriptUrl, scriptFileName, scriptRunner) = GetInstallScriptInfo();
147+
var (resourceName, scriptFileName, scriptRunner) = GetInstallScriptInfo();
147148

148-
// Download the install script
149+
// Extract the install script from embedded resources
149150
var scriptPath = Path.Combine(sdksDirectory, scriptFileName);
150-
using (var httpClient = new HttpClient())
151+
var assembly = Assembly.GetExecutingAssembly();
152+
using (var resourceStream = assembly.GetManifestResourceStream(resourceName))
151153
{
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+
}
155163
}
156164

157165
// Make the script executable on Unix-like systems
@@ -298,23 +306,23 @@ private string GetSdksDirectory()
298306
/// <summary>
299307
/// Gets the install script information based on the current platform.
300308
/// </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()
303311
{
304312
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
305313
{
306314
// Try pwsh first (PowerShell Core), then fall back to powershell (Windows PowerShell)
307315
var powerShellExecutable = GetAvailablePowerShell();
308316
return (
309-
"https://dot.net/v1/dotnet-install.ps1",
317+
"Aspire.Cli.Resources.dotnet-install.ps1",
310318
"dotnet-install.ps1",
311319
powerShellExecutable
312320
);
313321
}
314322
else
315323
{
316324
return (
317-
"https://dot.net/v1/dotnet-install.sh",
325+
"Aspire.Cli.Resources.dotnet-install.sh",
318326
"dotnet-install.sh",
319327
"bash"
320328
);

0 commit comments

Comments
 (0)