From 8d2733e1475c3038b2e3f83ff60c94a0ffe766a6 Mon Sep 17 00:00:00 2001 From: piotrp Date: Sun, 29 Nov 2015 10:58:13 -0800 Subject: [PATCH] PR Feedback --- src/Microsoft.DotNet.Cli.Utils/Command.cs | 12 ++--- src/Microsoft.DotNet.Cli.Utils/PathUtility.cs | 36 --------------- .../FileNameSuffixes.cs | 44 +++++++++++++++---- 3 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Microsoft.DotNet.Cli.Utils/Command.cs index fb72f5ea2..2a7933173 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Command.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Command.cs @@ -106,9 +106,9 @@ namespace Microsoft.DotNet.Cli.Utils { if (framework == null) return null; - var projectRootPath = PathUtility.GetProjectRootPath(); + var projectRootPath = Directory.GetCurrentDirectory(); - if (projectRootPath == null) return null; + if (!File.Exists(Path.Combine(projectRootPath, Project.FileName))) return null; var commandName = Path.GetFileNameWithoutExtension(executable); @@ -124,15 +124,15 @@ namespace Microsoft.DotNet.Cli.Utils .Where(n => Path.GetFileNameWithoutExtension(n) == commandName) .ToList(); - return fileNames.Contains(commandName + FileNameSuffixes.ExeSuffix) && - fileNames.Contains(commandName + FileNameSuffixes.DynamicLib) && - fileNames.Contains(commandName + FileNameSuffixes.Deps); + return fileNames.Contains(commandName + FileNameSuffixes.DotNet.Exe) && + fileNames.Contains(commandName + FileNameSuffixes.DotNet.DynamicLib) && + fileNames.Contains(commandName + FileNameSuffixes.DotNet.Deps); }); if (commandPackage == null) return null; var commandPath = commandPackage.Library.Files - .First(f => Path.GetFileName(f) == commandName + FileNameSuffixes.ExeSuffix); + .First(f => Path.GetFileName(f) == commandName + FileNameSuffixes.DotNet.Exe); return Path.Combine(projectContext.PackagesDirectory, commandPackage.Path, commandPath); } diff --git a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs index afaaf6b0d..c06b41e3f 100644 --- a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs +++ b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs @@ -199,41 +199,5 @@ namespace Microsoft.DotNet.Tools.Common return GetPathWithBackSlashes(path); } } - - public static string GetProjectRootPath(string path = null) - { - var directoryPath = Directory.GetCurrentDirectory(); - - if (path != null) - { - try - { - directoryPath = Path.GetDirectoryName(path); - } - catch (ArgumentException) - { - throw new ArgumentException("Illegal Characters in Path", nameof(directoryPath)); - } - - if(!Directory.Exists(directoryPath)) - { - throw new ArgumentException($"'{directoryPath}' does not exist.", nameof(directoryPath)); - } - } - - string projectRootPath = null; - - var directory = new DirectoryInfo(directoryPath); - - while (projectRootPath == null && directory != null) - { - if (directory.GetFiles("project.json").Any()) - projectRootPath = directory.FullName; - - directory = directory.GetFiles("global.json").Any() ? null : directory.Parent; - } - - return projectRootPath; - } } } \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs b/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs index 9fe8d2b56..ef535425c 100644 --- a/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs +++ b/src/Microsoft.DotNet.ProjectModel/FileNameSuffixes.cs @@ -4,18 +4,44 @@ namespace Microsoft.DotNet.ProjectModel { public static class FileNameSuffixes { - public static readonly string DynamicLib = - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : - RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? ".dylib" : ".so"; + public static PlatformFileNameSuffixes DotNet { get; } = new PlatformFileNameSuffixes + { + DynamicLib = ".dll", + Exe = ".exe", + ProgramDatabase = ".pdb", + StaticLib = ".lib", + Deps = ".deps", + }; - public static readonly string ExeSuffix = - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty; + public static PlatformFileNameSuffixes Windows { get; } = new PlatformFileNameSuffixes + { + DynamicLib = ".dll", + Exe = ".exe", + ProgramDatabase = ".pdb", + StaticLib = ".lib", + Deps = ".deps", + }; - public const string ProgramDatabase = ".pdb"; + public static PlatformFileNameSuffixes OSX { get; } = new PlatformFileNameSuffixes + { + DynamicLib = ".dylib", + Exe = "", + ProgramDatabase = ".pdb", + StaticLib = ".a", + Deps = ".deps" + }; - public static readonly string StaticLib = - RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".lib" : ".a" ; + public struct PlatformFileNameSuffixes + { + public string DynamicLib { get; set; } - public static readonly string Deps = ".deps"; + public string Exe { get; set; } + + public string ProgramDatabase { get; set; } + + public string StaticLib { get; set; } + + public string Deps { get; set; } + } } }