Skip to content
Closed
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
1 change: 0 additions & 1 deletion src/Aspire.Cli/Aspire.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="Semver" />
<PackageReference Include="Sigstore" />
<PackageReference Include="System.IO.Hashing" />
<PackageReference Include="Tuf" />
<PackageReference Include="ModelContextProtocol" />
</ItemGroup>
Expand Down
12 changes: 11 additions & 1 deletion src/Aspire.Cli/DotNet/DotNetCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ private string GetMsBuildServerValue()

internal static string GetBackchannelSocketPath()
{
return CliPathHelper.CreateSocketPath("cli.sock");
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var aspireCliPath = Path.Combine(homeDirectory, ".aspire", "cli", "backchannels");

if (!Directory.Exists(aspireCliPath))
{
Directory.CreateDirectory(aspireCliPath);
}

var uniqueSocketPathSegment = Guid.NewGuid().ToString("N");
var socketPath = Path.Combine(aspireCliPath, $"cli.sock.{uniqueSocketPathSegment}");
return socketPath;
}

private async Task<int> ExecuteAsync(
Expand Down
4 changes: 3 additions & 1 deletion src/Aspire.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public class Program
{
private static string GetUsersAspirePath()
{
return CliPathHelper.GetAspireHomeDirectory();
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var aspirePath = Path.Combine(homeDirectory, ".aspire");
return aspirePath;
}

/// <summary>
Expand Down
25 changes: 24 additions & 1 deletion src/Aspire.Cli/Projects/AppHostServerProject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Cryptography;
using System.Text;
using Aspire.Cli.Bundles;
using Aspire.Cli.Configuration;
using Aspire.Cli.DotNet;
Expand Down Expand Up @@ -34,7 +36,28 @@ internal sealed class AppHostServerProjectFactory(
{
public async Task<IAppHostServerProject> CreateAsync(string appPath, CancellationToken cancellationToken = default)
{
var socketPath = CliPathHelper.CreateSocketPath("apphost.sock");
// Normalize the path
var normalizedPath = Path.GetFullPath(appPath);
normalizedPath = new Uri(normalizedPath).LocalPath;
normalizedPath = OperatingSystem.IsWindows() ? normalizedPath.ToLowerInvariant() : normalizedPath;

// Generate socket path based on app path hash (deterministic for same project)
var pathHash = SHA256.HashData(Encoding.UTF8.GetBytes(normalizedPath));
var socketName = Convert.ToHexString(pathHash)[..12].ToLowerInvariant() + ".sock";

string socketPath;
if (OperatingSystem.IsWindows())
{
// Windows uses named pipes
socketPath = socketName;
}
else
{
// Unix uses domain sockets
var socketDir = Path.Combine(Path.GetTempPath(), ".aspire", "sockets");
Directory.CreateDirectory(socketDir);
socketPath = Path.Combine(socketDir, socketName);
}

// Priority 1: Check for dev mode (ASPIRE_REPO_ROOT or running from Aspire source repo)
var repoRoot = AspireRepositoryDetector.DetectRepositoryRoot(appPath);
Expand Down
6 changes: 5 additions & 1 deletion src/Aspire.Cli/Projects/GuestAppHostProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,11 @@ await GenerateCodeViaRpcAsync(
/// </summary>
private static string GetBackchannelSocketPath()
{
return CliPathHelper.CreateSocketPath("cli.sock");
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var aspireCliPath = Path.Combine(homeDirectory, ".aspire", "cli", "backchannels");
Directory.CreateDirectory(aspireCliPath);
var socketName = $"{Guid.NewGuid():N}.sock";
return Path.Combine(aspireCliPath, socketName);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/Projects/ProjectUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task<ProjectUpdateResult> UpdateProjectAsync(FileInfo projectFile,
cancellationToken: cancellationToken);

var nugetConfigDirectory = new DirectoryInfo(selectedPathForNewNuGetConfigFile);
await NuGetConfigMerger.CreateOrUpdateAsync(nugetConfigDirectory, channel, AnalyzeAndConfirmNuGetConfigChanges, cancellationToken: cancellationToken);
await NuGetConfigMerger.CreateOrUpdateAsync(nugetConfigDirectory, channel, AnalyzeAndConfirmNuGetConfigChanges, cancellationToken);
}

interactionService.DisplayEmptyLine();
Expand Down
10 changes: 4 additions & 6 deletions src/Aspire.Cli/Utils/AppHostHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ internal static async Task<int> BuildAppHostAsync(IDotNetCliRunner runner, IInte
/// Computes the auxiliary backchannel socket path prefix for a given AppHost project file.
/// </summary>
/// <remarks>
/// Since socket names now include a randomized instance hash and the AppHost's PID
/// (e.g., <c>auxi.sock.{hash}.{instanceHash}.{pid}</c>),
/// Since socket names now include the AppHost's PID (e.g., <c>auxi.sock.{hash}.{pid}</c>),
/// the CLI cannot compute the exact socket path. Use this prefix with a glob pattern
/// to find matching sockets, or use <see cref="FindMatchingSockets"/> instead.
/// </remarks>
Expand All @@ -107,16 +106,15 @@ internal static string[] FindMatchingSockets(string appHostPath, string homeDire
/// Extracts the hash portion from an auxiliary socket path.
/// </summary>
/// <remarks>
/// Works with old format (<c>auxi.sock.{hash}</c>), previous format (<c>auxi.sock.{hash}.{pid}</c>),
/// and current format (<c>auxi.sock.{hash}.{instanceHash}.{pid}</c>).
/// Works with both old format (<c>auxi.sock.{hash}</c>) and new format (<c>auxi.sock.{hash}.{pid}</c>).
/// </remarks>
/// <param name="socketPath">The full socket path (e.g., "/path/to/auxi.sock.b67075ff12d56865.a1b2c3d4e5f6.12345").</param>
/// <param name="socketPath">The full socket path (e.g., "/path/to/auxi.sock.b67075ff12d56865.12345").</param>
/// <returns>The hash portion (e.g., "b67075ff12d56865"), or null if the format is unrecognized.</returns>
internal static string? ExtractHashFromSocketPath(string socketPath)
=> BackchannelConstants.ExtractHash(socketPath);

/// <summary>
/// Extracts the PID from an auxiliary socket path when one is present.
/// Extracts the PID from an auxiliary socket path (new format only).
/// </summary>
/// <param name="socketPath">The full socket path.</param>
/// <returns>The PID if present and valid, or null for old format sockets.</returns>
Expand Down
39 changes: 0 additions & 39 deletions src/Aspire.Cli/Utils/CliPathHelper.cs

This file was deleted.

Loading
Loading