Beispiel #1
0
        private static bool TryParsePaths(IEnumerable <string> values, out ImmutableArray <string> paths)
        {
            paths = ImmutableArray <string> .Empty;

            if (values.Any())
            {
                if (!TryEnsureFullPath(values, out ImmutableArray <string> paths2))
                {
                    return(false);
                }

                paths = paths.AddRange(paths2);
            }

            if (Console.IsInputRedirected)
            {
                if (!TryEnsureFullPath(
                        ConsoleHelpers.ReadRedirectedInputAsLines().Where(f => !string.IsNullOrEmpty(f)),
                        out ImmutableArray <string> paths2))
                {
                    return(false);
                }

                paths = paths.AddRange(paths2);
            }

            if (!paths.IsEmpty)
            {
                return(true);
            }

            string directoryPath = Environment.CurrentDirectory;

            if (!TryFindFile(Directory.EnumerateFiles(directoryPath, "*.sln", SearchOption.TopDirectoryOnly), out string solutionPath))
            {
                WriteLine($"Multiple MSBuild solution files found in '{directoryPath}'", Verbosity.Quiet);
                return(false);
            }

            if (!TryFindFile(
                    Directory.EnumerateFiles(directoryPath, "*.*proj", SearchOption.TopDirectoryOnly)
                    .Where(f => !string.Equals(".xproj", Path.GetExtension(f), StringComparison.OrdinalIgnoreCase)),
                    out string projectPath))
            {
                WriteLine($"Multiple MSBuild projects files found in '{directoryPath}'", Verbosity.Quiet);
                return(false);
            }

            if (solutionPath != null)
            {
                if (projectPath != null)
                {
                    WriteLine($"Both MSBuild project file and solution file found in '{directoryPath}'", Verbosity.Quiet);
                    return(false);
                }

                paths = ImmutableArray.Create(solutionPath);
                return(true);
            }
            else if (projectPath != null)
            {
                paths = ImmutableArray.Create(projectPath);
                return(true);
            }
            else
            {
                WriteLine($"Could not find MSBuild project or solution file in '{directoryPath}'", Verbosity.Quiet);
                return(false);
            }