From f116a47ed15f19be3fb3686f5bdcbb824026e315 Mon Sep 17 00:00:00 2001 From: doingnz Date: Tue, 13 Feb 2024 23:21:03 +1300 Subject: [PATCH 1/2] Add missing quotes and refactor path handling for App Run Meadow command. Apply the same edits as #463 to the App Run command. Also correctly decode path when a project file reference is supplied. --- .../Commands/Current/App/AppRunCommand.cs | 22 +++++++++++++------ Source/v2/Meadow.Package/PackageManager.cs | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs index 3bb2ea55..a6d7f3a4 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs @@ -1,4 +1,5 @@ using CliFx.Attributes; +using CliFx.Exceptions; using Meadow.Hcom; using Meadow.Package; using Microsoft.Extensions.Logging; @@ -17,7 +18,7 @@ public class AppRunCommand : BaseDeviceCommand [CommandOption('c', Description = "The build configuration to compile", IsRequired = false)] public string? Configuration { get; set; } - [CommandParameter(0, Name = "Path to folder containing the built application", IsRequired = false)] + [CommandParameter(0, Name = "Path to folder containing the application to build.", IsRequired = false)] public string? Path { get; init; } public AppRunCommand(IPackageManager packageManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) @@ -28,21 +29,28 @@ public AppRunCommand(IPackageManager packageManager, MeadowConnectionManager con protected override async ValueTask ExecuteCommand() { - var connection = await GetCurrentConnection(); + string path = Path ?? Directory.GetCurrentDirectory(); - if (connection == null) + // is the path a file? + if (!File.Exists(path)) { - return; + // is it a valid directory? + if (!Directory.Exists(path)) + { + throw new CommandException($"Invalid application path '{path}'", (int)CommandErrors.FileNotFound); + } } - string path = Path ?? AppDomain.CurrentDomain.BaseDirectory; + Configuration ??= "Release"; - if (!Directory.Exists(path)) + var connection = await GetCurrentConnection(); + + if (connection == null) { - Logger?.LogError($"Target directory '{path}' not found"); return; } + var lastFile = string.Empty; // in order to deploy, the runtime must be disabled diff --git a/Source/v2/Meadow.Package/PackageManager.cs b/Source/v2/Meadow.Package/PackageManager.cs index 5f88a50d..7c275a68 100644 --- a/Source/v2/Meadow.Package/PackageManager.cs +++ b/Source/v2/Meadow.Package/PackageManager.cs @@ -31,7 +31,7 @@ private bool CleanApplication(string projectFilePath, string configuration = "Re { var proc = new Process(); proc.StartInfo.FileName = "dotnet"; - proc.StartInfo.Arguments = $"clean {projectFilePath} -c {configuration}"; + proc.StartInfo.Arguments = $"clean \"{projectFilePath}\" -c {configuration}"; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.ErrorDialog = false; @@ -230,7 +230,7 @@ private void CreateEntry(ZipArchive archive, string fromFile, string entryPath) public static FileInfo[] GetAvailableBuiltConfigurations(string rootFolder, string appName = "App.dll") { - rootFolder = Path.GetFullPath(rootFolder); + rootFolder = Path.GetDirectoryName(rootFolder); if (!Directory.Exists(rootFolder)) { throw new DirectoryNotFoundException($"Directory not found '{rootFolder}'. Check path to project file."); } //see if this is a fully qualified path to the app.dll From b6b0aa916453e5943e8c419bc47a79cdfe4826e7 Mon Sep 17 00:00:00 2001 From: doingnz Date: Wed, 14 Feb 2024 01:22:34 +1300 Subject: [PATCH 2/2] Only call Path.GetDirectoryName() if the path points to a file To avoid dropping one level of path, check if path points to a project file or folder. --- Source/v2/Meadow.Package/PackageManager.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/v2/Meadow.Package/PackageManager.cs b/Source/v2/Meadow.Package/PackageManager.cs index 7c275a68..eead620f 100644 --- a/Source/v2/Meadow.Package/PackageManager.cs +++ b/Source/v2/Meadow.Package/PackageManager.cs @@ -230,7 +230,11 @@ private void CreateEntry(ZipArchive archive, string fromFile, string entryPath) public static FileInfo[] GetAvailableBuiltConfigurations(string rootFolder, string appName = "App.dll") { - rootFolder = Path.GetDirectoryName(rootFolder); + // check if we were give path to a project file, not the folder of the project file. + if (File.Exists(rootFolder)) + { + rootFolder = Path.GetDirectoryName(rootFolder) ?? ""; // extreact the folder name or if invalid, use the current directory. + } if (!Directory.Exists(rootFolder)) { throw new DirectoryNotFoundException($"Directory not found '{rootFolder}'. Check path to project file."); } //see if this is a fully qualified path to the app.dll