Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Aspire.Cli/Aspire.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<EnablePackageValidation>false</EnablePackageValidation>
<AssemblyName>aspire</AssemblyName>
<RootNamespace>Aspire.Cli</RootNamespace>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn);CS1591;CS1574</NoWarn>
<PublishAot>true</PublishAot>
<OptimizationPreference>Size</OptimizationPreference>
<DefineConstants>$(DefineConstants);CLI</DefineConstants>
Expand Down Expand Up @@ -89,6 +89,9 @@
<Compile Include="$(SharedDir)ConsoleLogs\SharedAIHelpers.cs" Link="ConsoleLogs\SharedAIHelpers.cs" />
<Compile Include="$(SharedDir)ConsoleLogs\TimestampParser.cs" Link="ConsoleLogs\TimestampParser.cs" />
<Compile Include="$(SharedDir)ConsoleLogs\UrlParser.cs" Link="ConsoleLogs\UrlParser.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting\LaunchSettings.cs" Link="LaunchProfiles\LaunchSettings.cs" />
<Compile Include="$(RepoRoot)src\Aspire.Hosting\LaunchProfile.cs" Link="LaunchProfiles\LaunchProfile.cs" />
<Compile Include="$(SharedDir)LaunchProfiles\LaunchSettingsSerializerContext.cs" Link="LaunchProfiles\LaunchSettingsSerializerContext.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ internal static async Task<IHost> BuildApplicationAsync(string[] args, Dictionar
builder.Services.AddSingleton<IEnvironmentCheck, DevCertsCheck>();
builder.Services.AddSingleton<IEnvironmentCheck, ContainerRuntimeCheck>();
builder.Services.AddSingleton<IEnvironmentCheck, DeprecatedAgentConfigCheck>();
builder.Services.AddSingleton<IEnvironmentCheck, PortAvailabilityCheck>();
builder.Services.AddSingleton<IEnvironmentChecker, EnvironmentChecker>();

// MCP server transport factory - creates transport only when needed to avoid
Expand Down
78 changes: 4 additions & 74 deletions src/Aspire.Cli/Projects/GuestAppHostProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Diagnostics;
using System.Net.Sockets;
using System.Text.Json;
using Aspire.Cli.Backchannel;
using Aspire.Cli.Certificates;
using Aspire.Cli.Configuration;
Expand Down Expand Up @@ -476,84 +475,15 @@ await GenerateCodeViaRpcAsync(

private Dictionary<string, string>? ReadLaunchSettingsEnvironmentVariables(DirectoryInfo directory)
{
// For guest apphosts, look for apphost.run.json
// similar to how .NET single-file apphosts use apphost.run.json
var apphostRunPath = Path.Combine(directory.FullName, "apphost.run.json");
var launchSettingsPath = Path.Combine(directory.FullName, "Properties", "launchSettings.json");

var configPath = File.Exists(apphostRunPath) ? apphostRunPath : launchSettingsPath;

if (!File.Exists(configPath))
var result = LaunchProfileHelper.ReadEnvironmentVariables(directory);
if (result is null)
{
_logger.LogDebug("No apphost.run.json or launchSettings.json found in {Path}", directory.FullName);
return null;
}

try
{
var json = File.ReadAllText(configPath);
using var doc = JsonDocument.Parse(json);

if (!doc.RootElement.TryGetProperty("profiles", out var profiles))
{
return null;
}

// Try to find the 'https' profile first, then fall back to the first profile
JsonElement? profileElement = null;
if (profiles.TryGetProperty("https", out var httpsProfile))
{
profileElement = httpsProfile;
}
else
{
// Use the first profile
using var enumerator = profiles.EnumerateObject();
if (enumerator.MoveNext())
{
profileElement = enumerator.Current.Value;
}
}

if (profileElement == null)
{
return null;
}

var result = new Dictionary<string, string>();

// Read applicationUrl and convert to ASPNETCORE_URLS
if (profileElement.Value.TryGetProperty("applicationUrl", out var appUrl) &&
appUrl.ValueKind == JsonValueKind.String)
{
result["ASPNETCORE_URLS"] = appUrl.GetString()!;
}

// Read environment variables
if (profileElement.Value.TryGetProperty("environmentVariables", out var envVars))
{
foreach (var prop in envVars.EnumerateObject())
{
if (prop.Value.ValueKind == JsonValueKind.String)
{
result[prop.Name] = prop.Value.GetString()!;
}
}
}

if (result.Count == 0)
{
return null;
}

_logger.LogDebug("Read {Count} environment variables from apphost.run.json", result.Count);
return result;
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to read launchSettings.json");
return null;
}
_logger.LogDebug("Read {Count} environment variables from launch profile", result.Count);
return result;
}

/// <inheritdoc />
Expand Down
Loading