Example #1
0
        public void Execute([NotNull] string solutionFile, [NotNull] string basePath)
        {
            if (solutionFile.IsAssigned())
            {
                _solutionReader = new SolutionReader(Path.Combine(basePath, solutionFile));

                _solutionReader.Execute();
            }

            _projectReader = new ProjectReader(basePath);

            var projectNames = _solutionReader.IsAssigned()
                ? _solutionReader.GetFullProjectNames()
                : _projectReader.GetFullProjectNames();

            _projectReader
            .Execute(projectNames)
            .ExtendProjectsWithSolutionProjects(_solutionReader?.Solution?.SolutionProjects)
            .ExtendProjectsWithBinaryReferences();

            if (!_projectReader.SdkProjects.Any(x => x.BinaryReferencedProjects.Any()))
            {
                "All clear.".WriteLine();

                return;
            }

            if (solutionFile.IsAssigned())
            {
                $"Projects referencing other projects as a binary file in solution '{solutionFile}':".WriteLine();
            }
            else
            {
                "Projects referencing other projects as a binary file:".WriteLine();
            }

            foreach (var sdkProject in _projectReader.SdkProjects)
            {
                foreach (var binaryReferencedProject in sdkProject.BinaryReferencedProjects)
                {
                    $"\tproject = {sdkProject.FileName}".WriteLine();
                    $"\t\treference = {binaryReferencedProject.AssemblyName}.dll".WriteLine();
                }
            }
        }
        public void Execute([NotNull] string solutionFile, [NotNull] string basePath)
        {
            if (solutionFile.IsAssigned())
            {
                _solutionReader = new SolutionReader(Path.Combine(basePath, solutionFile));

                _solutionReader.Execute();
            }

            _projectReader = new ProjectReader(basePath);

            var projectNames = _solutionReader.IsAssigned()
                ? _solutionReader.GetFullProjectNames()
                : _projectReader.GetFullProjectNames();

            _projectReader
            .Execute(projectNames)
            .ExtendProjectsWithProjectReferences()
            .ExtendProjectsWithAllSubProjectReferences()
            .ExtendProjectsWithAllRedundantProjectReferences();

            var projectsWithRedundantReferences = _projectReader
                                                  .SdkProjects
                                                  .Where(x => x.RedundantReferencedProjects.Any())
                                                  .ToList();

            var tab = new string(' ', 4);

            if (!projectsWithRedundantReferences.Any())
            {
                "No redundant project references found.".WriteLine();

                return;
            }

            using var sw = new StreamWriter(@".\redundant.txt");

            if (solutionFile.IsAssigned())
            {
                $"Redundant project references in solution '{solutionFile}':".WriteLine();
            }
            else
            {
                "Redundant project references:".WriteLine();
            }

            foreach (var projectWithRedundantReferences in projectsWithRedundantReferences)
            {
                var line = $@"{projectWithRedundantReferences.FileName.TrimStartIgnoreCase(basePath)}".WriteLine();

                sw.WriteLine(line);

                foreach (var redundantReferencedProject in projectWithRedundantReferences.RedundantReferencedProjects)
                {
                    line = $@"{tab} - {redundantReferencedProject.FileName.TrimStartIgnoreCase(basePath)}".WriteLine();

                    sw.WriteLine(line);
                }
            }

            "See => 'redundant.txt'".WriteLine();
        }