Skip to content

Commit

Permalink
fix directory resolution bug
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Jul 31, 2024
1 parent a7e1315 commit c35ca62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/Cli/dotnet/commands/dotnet-run/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ public static RunCommand FromParseResult(ParseResult parseResult)
if (parseResult.UsingRunCommandShorthandProjectOption())
{
Reporter.Output.WriteLine(LocalizableStrings.RunCommandProjectAbbreviationDeprecated.Yellow());
project = parseResult.GetRunCommandShorthandProjectValues().FirstOrDefault();
var possibleProject = parseResult.GetRunCommandShorthandProjectValues().FirstOrDefault();
if (Directory.Exists(possibleProject))
{
project = RunCommandParser.FindSingleProjectInDirectory(possibleProject);
}
else
{
project = possibleProject;
}
}

var command = new RunCommand(
noBuild: parseResult.HasOption(RunCommandParser.NoBuildOption),
project: project,
projectFileFullPath: project,
launchProfile: parseResult.GetValue(RunCommandParser.LaunchProfileOption),
noLaunchProfile: parseResult.HasOption(RunCommandParser.NoLaunchProfileOption),
noRestore: parseResult.HasOption(RunCommandParser.NoRestoreOption) || parseResult.HasOption(RunCommandParser.NoBuildOption),
Expand Down
14 changes: 7 additions & 7 deletions src/Cli/dotnet/commands/dotnet-run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class RunCommand
private record RunProperties(string? RunCommand, string? RunArguments, string? RunWorkingDirectory);

public bool NoBuild { get; private set; }
public string Project { get; private set; }
public string ProjectFileFullPath { get; private set; }
public string[] Args { get; set; }
public bool NoRestore { get; private set; }
public bool Interactive { get; private set; }
Expand All @@ -35,7 +35,7 @@ private record RunProperties(string? RunCommand, string? RunArguments, string? R

public RunCommand(
bool noBuild,
string project,
string projectFileFullPath,
string launchProfile,
bool noLaunchProfile,
bool noRestore,
Expand All @@ -44,7 +44,7 @@ public RunCommand(
string[] args)
{
NoBuild = noBuild;
Project = project;
ProjectFileFullPath = projectFileFullPath;
LaunchProfile = launchProfile;
NoLaunchProfile = noLaunchProfile;
Args = args;
Expand Down Expand Up @@ -81,7 +81,7 @@ public int Execute()
catch (InvalidProjectFileException e)
{
throw new GracefulException(
string.Format(LocalizableStrings.RunCommandSpecifiecFileIsNotAValidProject, Project),
string.Format(LocalizableStrings.RunCommandSpecifiecFileIsNotAValidProject, ProjectFileFullPath),
e);
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel?
return true;
}

var launchSettingsPath = TryFindLaunchSettings(Project);
var launchSettingsPath = TryFindLaunchSettings(ProjectFileFullPath);
if (!File.Exists(launchSettingsPath))
{
if (!string.IsNullOrEmpty(LaunchProfile))
Expand Down Expand Up @@ -189,7 +189,7 @@ private void EnsureProjectIsBuilt()
{
var buildResult =
new RestoringCommand(
RestoreArgs.Prepend(Project),
RestoreArgs.Prepend(ProjectFileFullPath),
NoRestore,
advertiseWorkloadUpdates: false
).Execute();
Expand Down Expand Up @@ -224,7 +224,7 @@ private string[] GetRestoreArguments(IEnumerable<string> cliRestoreArgs)
private ICommand GetTargetCommand()
{
// TODO for MSBuild usage here: need to sync loggers (primarily binlog) used with this evaluation
var project = EvaluateProject(Project, RestoreArgs);
var project = EvaluateProject(ProjectFileFullPath, RestoreArgs);
InvokeRunArgumentsTarget(project);
var runProperties = ReadRunPropertiesFromProject(project, Args);
var command = CreateCommandFromRunProperties(project, runProperties);
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/commands/dotnet-run/RunCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static class RunCommandParser
},
};

private static string FindSingleProjectInDirectory(string directory)
public static string FindSingleProjectInDirectory(string directory)
{
string[] projectFiles = Directory.GetFiles(directory, "*.*proj");

Expand Down

0 comments on commit c35ca62

Please sign in to comment.