Skip to content
Merged
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
16 changes: 8 additions & 8 deletions src/Aspire.Cli/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ internal sealed class NewCommand : BaseCommand
// interrogate the various options and add them. For now we will
// keep it simple.
(string TemplateName, string TemplateDescription, string? PathAppendage)[] validTemplates = [
("aspire-starter", "Aspire Starter App", "src") ,
("aspire", "Aspire Empty App", "src"),
("aspire-apphost", "Aspire App Host", null),
("aspire-servicedefaults", "Aspire Service Defaults", null),
("aspire-mstest", "Aspire Test Project (MSTest)", null),
("aspire-nunit", "Aspire Test Project (NUnit)", null),
("aspire-xunit", "Aspire Test Project (xUnit)", null)
("aspire-starter", "Aspire Starter App", "./src") ,
("aspire", "Aspire Empty App", "./src"),
("aspire-apphost", "Aspire App Host", "./"),
("aspire-servicedefaults", "Aspire Service Defaults", "./"),
("aspire-mstest", "Aspire Test Project (MSTest)", "./"),
("aspire-nunit", "Aspire Test Project (NUnit)", "./"),
("aspire-xunit", "Aspire Test Project (xUnit)", "./")
];

if (parseResult.GetValue<string?>("template") is { } templateName && validTemplates.SingleOrDefault(t => t.TemplateName == templateName) is { } template)
Expand Down Expand Up @@ -92,7 +92,7 @@ private static async Task<string> GetOutputPathAsync(ParseResult parseResult, st
{
outputPath = await PromptUtils.PromptForStringAsync(
"Enter the output path:",
defaultValue: Path.Combine(Environment.CurrentDirectory, pathAppendage ?? string.Empty),
defaultValue: pathAppendage ?? ".",
cancellationToken: cancellationToken
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Aspire.Cli/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public RunCommand(DotNetCliRunner runner) : base("run", "Run an Aspire app host

_runner = runner;

var projectOption = new Option<FileInfo?>("--project");
projectOption.Validators.Add(ProjectFileHelper.ValidateProjectOption);
Options.Add(projectOption);
var projectArgument = new Argument<FileInfo?>("project");
projectArgument.Validators.Add(ProjectFileHelper.ValidateProjectArgument);
Arguments.Add(projectArgument);

var watchOption = new Option<bool>("--watch", "-w");
Options.Add(watchOption);
Expand All @@ -35,7 +35,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
{
using var activity = _activitySource.StartActivity();

var passedAppHostProjectFile = parseResult.GetValue<FileInfo?>("--project");
var passedAppHostProjectFile = parseResult.GetValue<FileInfo?>("project");
var effectiveAppHostProjectFile = ProjectFileHelper.UseOrFindAppHostProjectFile(passedAppHostProjectFile);

if (effectiveAppHostProjectFile is null)
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Cli/DotNetCliRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed class DotNetCliRunner(ILogger<DotNetCliRunner> logger, IServiceP
{
using var activity = _activitySource.StartActivity();

string[] cliArgs = ["msbuild", "-getproperty:IsAspireHost,AspireHostingSDKVersion"];
string[] cliArgs = ["msbuild", "-getproperty:IsAspireHost,AspireHostingSDKVersion", projectFile.FullName];

string? stdout = null;
string? stderr = null;
Expand Down
32 changes: 32 additions & 0 deletions src/Aspire.Cli/Utils/ProjectFileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ internal static class ProjectFileHelper
};
}

internal static void ValidateProjectArgument(ArgumentResult result)
{
var value = result.GetValueOrDefault<FileInfo?>();

if (value is null)
{
// Having no value here is fine, but there has to
// be a single csproj file in the current
// working directory.
var csprojFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.csproj");

if (csprojFiles.Length > 1)
{
result.AddError("The project argument was not specified and multiple *.csproj files were detected.");
return;
}
else if (csprojFiles.Length == 0)
{
result.AddError("The project argument was not specified and no *.csproj files were detected.");
return;
}

return;
}

if (!File.Exists(value.FullName))
{
result.AddError("The specified project file does not exist.");
return;
}
}

internal static void ValidateProjectOption(OptionResult result)
{
var value = result.GetValueOrDefault<FileInfo?>();
Expand Down
Loading