Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for Dapr CLI on PATH #4081

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

philliphoff
Copy link
Contributor

@philliphoff philliphoff commented May 4, 2024

Currently the Dapr CLI is looked for at several very specific locations, depending on the platform. With this change, Aspire will default to the Dapr CLI found on PATH, if any. If none is found, falls back to one of those specific locations.

Resolves #2219

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 4, 2024

try
{
process = Process.Start(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this instead?

private static string? FindFullPathFromPath(string command) => FindFullPathFromPath(command, Environment.GetEnvironmentVariable("PATH"), Path.PathSeparator, File.Exists);
private static string? FindFullPathFromPath(string command, string? pathVariable, char pathSeparator, Func<string, bool> fileExists)
{
Debug.Assert(!string.IsNullOrWhiteSpace(command));
if (OperatingSystem.IsWindows())
{
command += ".cmd";
}
foreach (var directory in (pathVariable ?? string.Empty).Split(pathSeparator))
{
var fullPath = Path.Combine(directory, command);
if (fileExists(fullPath))
{
return fullPath;
}
}
return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aspire.Hosting.Dapr should allow specifying CLI executable location
2 participants