Skip to content

Commit e866bbb

Browse files
Copilotdavidfowl
andcommitted
Replace GetHashCode with SHA256 for stable persistent hashing
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
1 parent 21873c3 commit e866bbb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Aspire.Cli/Commands/DeployCommand.cs

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

44
using System.CommandLine.Parsing;
5-
using System.Globalization;
5+
using System.Security.Cryptography;
6+
using System.Text;
67
using Aspire.Cli.Configuration;
78
using Aspire.Cli.DotNet;
89
using Aspire.Cli.Interaction;
@@ -31,10 +32,11 @@ protected override string CreateDefaultOutputPath(ArgumentResult result)
3132
var projectFile = result.GetValue<FileInfo?>("--project");
3233
var sourcePath = projectFile?.FullName ?? Environment.CurrentDirectory;
3334

34-
// Create a stable hash of the source path for the directory name
35-
var sourceHash = sourcePath.GetHashCode().ToString("x8", CultureInfo.InvariantCulture);
35+
// Create a stable hash of the source path for the directory name using SHA256
36+
var sourceHash = SHA256.HashData(Encoding.UTF8.GetBytes(sourcePath));
37+
var hashString = Convert.ToHexString(sourceHash)[..8].ToLowerInvariant();
3638

37-
return Directory.CreateTempSubdirectory($"aspire-deploy-{sourceHash}-").FullName;
39+
return Directory.CreateTempSubdirectory($"aspire-deploy-{hashString}-").FullName;
3840
}
3941

4042
protected override string[] GetRunArguments(string fullyQualifiedOutputPath, string[] unmatchedTokens) =>

0 commit comments

Comments
 (0)