Ejemplo n.º 1
0
        private void GetProjectsInSolution(string solutionFilePath, string[] projects = null)
        {
            projects = projects ?? new string[] { };
            var supportedType = new[]
            {
                SolutionProjectType.KnownToBeMSBuildFormat,
                SolutionProjectType.WebProject
            };

            var solution = SolutionFile.Parse(solutionFilePath);

            foreach (var project in solution.ProjectsInOrder)
            {
                if (!supportedType.Contains(project.ProjectType))
                {
                    continue;
                }
                if (projects.Length > 0 && !projects.Contains(project.ProjectName))
                {
                    continue;
                }

                GetProject(project.AbsolutePath);
            }
        }
Ejemplo n.º 2
0
        public void Merge_TrivialLines()
        {
            var baseSln    = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Unity.sln", @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 16
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Assembly-CSharp"", ""Assembly-CSharp.csproj"", ""{1E7138DC-D3E2-51A8-4059-67524470B2E7}""
EndProject
Global
EndGlobal
".Trim());
            var overlaySln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Server.sln", @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1
Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Nantoka.Server"", ""..\Nantoka.Server\Nantoka.Server.csproj"", ""{053476FC-B8B2-4A14-AED2-3733DFD5DFC3}""
EndProject
Global
EndGlobal
".Trim());

            var mergedSolutionFile = SlnMerge.Merge(baseSln, overlaySln, new SlnMergeSettings(), SlnMergeNullLogger.Instance);
            var content            = mergedSolutionFile.ToFileContent();

            Assert.Equal(@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 16
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Assembly-CSharp"", ""Assembly-CSharp.csproj"", ""{1E7138DC-D3E2-51A8-4059-67524470B2E7}""
EndProject
Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Nantoka.Server"", ""..\Nantoka.Server\Nantoka.Server.csproj"", ""{053476FC-B8B2-4A14-AED2-3733DFD5DFC3}""
EndProject
Global
EndGlobal
".Trim(), content.Trim());
        }
Ejemplo n.º 3
0
        public static CsSolution ParseSolution(string solutionFilePath)
        {
            var          solution     = new CsSolution();
            SolutionFile solutionFile = SolutionFile.Parse(solutionFilePath);
            var          projectFiles = solutionFile.ProjectsInOrder;
            var          projects     = new List <CsProject>();

            foreach (var projectFile in projectFiles)
            {
                if (!Path.GetExtension(projectFile.AbsolutePath).Equals(".csproj"))
                {
                    //TODO: support recursive folder search
                    Console.WriteLine($"Skipping path '{projectFile.AbsolutePath}'...");
                    continue;
                }

                ProjectRootElement projectToParse = ProjectRootElement.Open(projectFile.AbsolutePath);
                var csProject = new CsProject()
                {
                    Name = projectFile.ProjectName
                };
                csProject.Classes = ParseProjectRoot(projectFile, projectToParse);
                projects.Add(csProject);
            }
            solution.Projects = projects;
            return(solution);
        }
Ejemplo n.º 4
0
        private static void SwitchToProjects(ReferenceSwitcherConfiguration configuration, IConsoleHost host)
        {
            var solution = SolutionFile.Parse(configuration.ActualSolution);

            foreach (var solutionProject in solution.ProjectsInOrder)
            {
                if (solutionProject.ProjectType != SolutionProjectType.SolutionFolder)
                {
                    try
                    {
                        using (var projectInformation = ProjectExtensions.LoadProject(solutionProject.AbsolutePath))
                        {
                            foreach (var mapping in configuration.Mappings)
                            {
                                var packageName  = mapping.Key;
                                var projectPaths = mapping.Value.Select(p => configuration.GetActualPath(p)).ToList();

                                var switchedProjects = SwitchToProject(configuration, solutionProject, projectInformation, packageName, projectPaths, host);
                                foreach (var s in switchedProjects)
                                {
                                    host.WriteMessage("Project " + Path.GetFileName(s.Key) + " packages:\n");
                                    host.WriteMessage("    " + packageName + " v" + s.Value + "\n    replaced by:\n");
                                    projectPaths.ForEach(p => host.WriteMessage("    " + Path.GetFileName(p) + "\n"));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        host.WriteError("The project '" + solutionProject.AbsolutePath + "' could not be loaded: " +
                                        e.Message + "\n");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static Microsoft.Build.Evaluation.Project[] GetMsBuildProjects(this Solution solution)
        {
            var solutionFullName = solution.FullName;

            if (!string.IsNullOrEmpty(solutionFullName))
            {
                var solutionFile = SolutionFile.Parse(solutionFullName);
                var projects     = solutionFile.ProjectsInOrder
                                   .Where(projectInSolution => projectInSolution.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
                                   .Select(project => Path.GetFullPath(project.AbsolutePath)).Select(path => {
                    try {
                        var globalProperties  = new Dictionary <string, string>();
                        var configurationName = DteExtensions.DTE.Solution.Projects()
                                                .FirstOrDefault(project1 => GetFullName(project1, path) == 0)?.ConfigurationManager
                                                .ActiveConfiguration.ConfigurationName ?? "Debug";
                        globalProperties.Add("Configuration", configurationName);
                        var projectCollection = new ProjectCollection(globalProperties);
                        return(new Microsoft.Build.Evaluation.Project(path, null, null, projectCollection));
                    }
                    catch (Exception e) {
                        DteExtensions.DTE.LogError($"Path={path}{Environment.NewLine}{e}");
                        DteExtensions.DTE.WriteToOutput($"Path={path}{Environment.NewLine}{e}");
                        return(null);
                    }
                }).Where(project => project != null).ToArray();
                return(projects);
            }
            return(Enumerable.Empty <Microsoft.Build.Evaluation.Project>().ToArray());
        }
Ejemplo n.º 6
0
        public DomainSettingsModel(string concern, string operation, PatternDirectoryType patternType, GroupByType groupBy)
        {
            var solutionFile = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln").FirstOrDefault();

            var solutionInfo = SolutionFile.Parse(solutionFile);

            var projectList = solutionInfo.ProjectsInOrder;

            foreach (var proj in projectList)
            {
                if (!proj.ProjectName.Contains(".Logic") &&
                    !proj.ProjectName.Contains(".Domain"))
                {
                    continue;
                }

                Concern     = concern;
                Operation   = operation;
                PatternType = patternType;

                ProjectName        = proj.RelativePath;
                DomainName         = proj.ProjectName;
                DomainAbsolutePath = ResolveDomainAbsolutePath(proj.AbsolutePath);
                PatternFileType    = PatternFileNameResolver.Resolve(patternType);
                ClassName          = $"{concern}{operation}{PatternFileNameResolver.Resolve(patternType)}";
                GroupingStrategy   = groupBy;
            }

            LogUtility.Info($"ProjectName: {ProjectName}");
            LogUtility.Info($"DomainName: {DomainName}");
            LogUtility.Info($"DomainAbsolutePath: {DomainAbsolutePath}");
        }
Ejemplo n.º 7
0
        public static SolutionInfo Create(string filePath, string configName)
        {
            var sln = SolutionFile.Parse(filePath);

            if (string.IsNullOrEmpty(configName))
            {
                configName = sln.GetDefaultConfigurationName();
            }

            var projects = new List <string>();

            var config = sln.SolutionConfigurations.FirstOrDefault(c => c.ConfigurationName == configName);

            if (config == null)
            {
                throw new InvalidOperationException($"A solution configuration by the name of '{configName}' was not found in '{filePath}'");
            }

            foreach (var project in sln.ProjectsInOrder
                     .Where(p =>
                            p.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat && // skips solution folders
                            p.ProjectConfigurations.TryGetValue(config.FullName, out var projectConfig) &&
                            projectConfig.IncludeInBuild))
            {
                projects.Add(project.AbsolutePath.Replace('\\', '/'));
            }

            return(new SolutionInfo(filePath, projects.ToArray()));
        }
Ejemplo n.º 8
0
        public void SolutionFile_Parse_simple_solution()
        {
            var solution = SolutionFile.Parse(SimpleSolutionContent);

            Assert.NotNull(solution.FormatVersion);
            Assert.Equal(new Version("9.00"), solution.FormatVersion);

            Assert.Null(solution.VisualStudioVersion);

            Assert.Equal(3, solution.Projects.Length);

            Assert.Equal("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", solution.Projects[0].ProjectTypeGuid);
            Assert.Equal("ConsoleApplication1", solution.Projects[0].ProjectName);
            Assert.Equal(@"ConsoleApplication1\ConsoleApplication1.vbproj", solution.Projects[0].RelativePath);
            Assert.Equal("{AB3413A6-D689-486D-B7F0-A095371B3F13}", solution.Projects[0].ProjectGuid);

            Assert.Equal("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", solution.Projects[1].ProjectTypeGuid);
            Assert.Equal("vbClassLibrary", solution.Projects[1].ProjectName);
            Assert.Equal(@"vbClassLibrary\vbClassLibrary.vbproj", solution.Projects[1].RelativePath);
            Assert.Equal("{BA333A76-4511-47B8-8DF4-CA51C303AD0B}", solution.Projects[1].ProjectGuid);

            Assert.Equal("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", solution.Projects[2].ProjectTypeGuid);
            Assert.Equal("ClassLibrary1", solution.Projects[2].ProjectName);
            Assert.Equal(@"ClassLibrary1\ClassLibrary1.csproj", solution.Projects[2].RelativePath);
            Assert.Equal("{DEBCE986-61B9-435E-8018-44B9EF751655}", solution.Projects[2].ProjectGuid);

            Assert.Equal(3, solution.GlobalSections.Length);
            Assert.Equal("SolutionConfigurationPlatforms", solution.GlobalSections[0].Name);
            Assert.Equal("ProjectConfigurationPlatforms", solution.GlobalSections[1].Name);
            Assert.Equal("SolutionProperties", solution.GlobalSections[2].Name);
        }
Ejemplo n.º 9
0
        public void SolutionFile_Parse_unity_solution()
        {
            var solution = SolutionFile.Parse(UnitySolutionContent);

            Assert.NotNull(solution.FormatVersion);
            Assert.Equal(new Version("11.00"), solution.FormatVersion);

            Assert.Null(solution.VisualStudioVersion);

            Assert.Equal(3, solution.Projects.Length);

            Assert.Equal("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", solution.Projects[0].ProjectTypeGuid);
            Assert.Equal("LeopotamGroupLibrary", solution.Projects[0].ProjectName);
            Assert.Equal("Assembly-CSharp.csproj", solution.Projects[0].RelativePath);
            Assert.Equal("{0279C7A5-B8B1-345F-ED42-A58232A100B3}", solution.Projects[0].ProjectGuid);

            Assert.Equal("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", solution.Projects[1].ProjectTypeGuid);
            Assert.Equal("LeopotamGroupLibrary", solution.Projects[1].ProjectName);
            Assert.Equal("Assembly-CSharp-firstpass.csproj", solution.Projects[1].RelativePath);
            Assert.Equal("{CD80764A-B5E2-C644-F0D0-A85E486306D8}", solution.Projects[1].ProjectGuid);

            Assert.Equal("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", solution.Projects[2].ProjectTypeGuid);
            Assert.Equal("LeopotamGroupLibrary", solution.Projects[2].ProjectName);
            Assert.Equal("Assembly-CSharp-Editor.csproj", solution.Projects[2].RelativePath);
            Assert.Equal("{BEDD06D2-DCFB-A6D5-CAC1-1320A679D62A}", solution.Projects[2].ProjectGuid);

            Assert.Equal(4, solution.GlobalSections.Length);
            Assert.Equal("SolutionConfigurationPlatforms", solution.GlobalSections[0].Name);
            Assert.Equal("ProjectConfigurationPlatforms", solution.GlobalSections[1].Name);
            Assert.Equal("SolutionProperties", solution.GlobalSections[2].Name);
            Assert.Equal("MonoDevelopProperties", solution.GlobalSections[3].Name);
        }
        public DomainSettingsModel(string concern, string operation, PatternDirectoryType patternType, GroupByType groupBy)
        {
            var solutionFile = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln").FirstOrDefault();
            var solutionInfo = SolutionFile.Parse(solutionFile);

            var projectList = solutionInfo.ProjectsInOrder;

            var proj =
                projectList.FirstOrDefault(x => x.ProjectName.Equals("Logic") || x.ProjectName.Equals("Domain"));

            if (proj == null)
            {
                throw new Exception("Missing domain or logic project in solution");
            }


            Concern     = concern;
            Operation   = operation;
            PatternType = patternType;

            ProjectName        = proj.RelativePath;
            DomainName         = proj.ProjectName;
            DomainAbsolutePath = ResolveDomainAbsolutePath(proj.AbsolutePath);
            PatternFileType    = PatternFileNameResolver.Resolve(patternType);
            ClassName          = $"{concern}{operation}{PatternFileNameResolver.Resolve(patternType)}";
            GroupingStrategy   = groupBy;

            //LogUtility.Info($"ProjectName: {ProjectName}");
            //LogUtility.Info($"DomainName: {DomainName}");
            //LogUtility.Info($"DomainAbsolutePath: {DomainAbsolutePath}");
        }
Ejemplo n.º 11
0
        public Task RunAsync()
        {
            var solutionFile = SolutionFile.Parse(this.VerbOptions.SolutionFile.FullName);
            var solutionName = Path.GetFileNameWithoutExtension(this.VerbOptions.SolutionFile.FullName);

            Solution solution = Solution.FromProjects(solutionName, solutionFile.ProjectsInOrder);

            var projects = this.VerbOptions.Projects;

            if (projects.Any())
            {
                var projectsToChange = solution.FindDependentsByName(projects);

                Epoch epoch = this.GetReleaseDate();

                foreach (var project in projectsToChange)
                {
                    project.IncreaseVersion(this.VerbOptions.VersionLevel, epoch);
                }

                if (this.VerbOptions.Commit)
                {
                    this.Save(projectsToChange);
                }

                return(this.OutputAsync(solutionName, projects, projectsToChange, epoch));
            }
            else
            {
                throw new ApplicationException("There isn't any project changed");
            }
        }
        protected override Task <SolutionInfo> GetSolutionInfoAsync(RepoFile repoFile)
        {
            var repo       = repoFile.PrimaryProject.Repo;
            var dispatcher = repo.AnalysisServices.TaskDispatcher;
            var services   = repo.AnalysisServices;
            var logger     = repo.AnalysisServices.Logger;

            var solutionFilePath = repoFile.FilePath;
            var binLog           = binLogFinder?.Invoke(solutionFilePath);

            if (!File.Exists(binLog))
            {
                logger?.LogWarning($"Couldn't find .binlog for {solutionFilePath}, reverting to MSBuildWorkspace");
                return(base.GetSolutionInfoAsync(repoFile));
            }

            var solutionFile = SolutionFile.Parse(new SourceTextReader(SourceText.From(services.ReadAllText(solutionFilePath))));

            SolutionInfoBuilder solutionInfo = new SolutionInfoBuilder(solutionFilePath, repo, binLog);

            foreach (var projectBlock in solutionFile.ProjectBlocks)
            {
                solutionInfo.StartLoadProject(projectBlock.ProjectPath);
            }

            if (solutionInfo.HasProjects)
            {
                repoFile.HasExplicitAnalyzer = true;
            }

            return(Task.FromResult(solutionInfo.Build()));
        }
Ejemplo n.º 13
0
        protected override void AnnotateFile(AnalysisServices services, RepoFile file, BoundSourceFileBuilder binder)
        {
            string solutionDirectory = Path.GetDirectoryName(file.FilePath);

            try
            {
                var defaultRepoProject = file.PrimaryProject.Repo.DefaultRepoProject;
                var repoRoot           = defaultRepoProject.ProjectDirectory;
                var solutionFile       = SolutionFile.Parse(new SourceTextReader(binder.SourceText));
                foreach (var projectBlock in solutionFile.ProjectBlocks)
                {
                    var projectPath = projectBlock.ParsedProjectPath.Value;
                    if (string.IsNullOrEmpty(projectPath))
                    {
                        continue;
                    }

                    var fullProjectPath = Path.GetFullPath(Path.Combine(solutionDirectory, projectPath));

                    var projectFileReference = BoundSourceFileBuilder.CreateFileReferenceSymbol(
                        defaultRepoProject.GetLogicalPath(fullProjectPath),
                        defaultRepoProject.ProjectId);

                    var span = projectBlock.ParsedProjectName.Span;
                    AnnotateReference(binder, projectFileReference, span);

                    span = projectBlock.ParsedProjectPath.Span;
                    AnnotateReference(binder, projectFileReference, span);
                }
            }
            catch (Exception ex)
            {
                services.Logger.LogExceptionError("AnnotateSolution", ex);
            }
        }
        public bool Run(ProjectInSolution project, UpdateProjectOptions options)
        {
            bool updated;

            if (!string.IsNullOrEmpty(options.ReplaceNameFrom) && !string.IsNullOrEmpty(options.ReplaceNameTo))
            {
                project.ProjectName =
                    project.ProjectName.ReplaceSmartIgnoreCase(options.ReplaceNameFrom, options.ReplaceNameTo);
                var oldRelativeDir = project.Folder.GetRelativePath(Path.GetDirectoryName(options.SolutionFullPath));
                updated = UpdateProject(oldRelativeDir, project.Folder, project, options.Preview, keepCsProjFileName: false);
            }
            else
            {
                string projectNewFolder = Path.Combine(Path.GetDirectoryName(project.Folder) ?? "", project.ProjectName);
                var    newRelativeDir   = projectNewFolder.GetRelativePath(Path.GetDirectoryName(options.SolutionFullPath));
                updated = UpdateProject(newRelativeDir, projectNewFolder, project, options.Preview, keepCsProjFileName: false);
            }

            if (!updated)
            {
                return(false);
            }

            SolutionFile slnFile = SolutionFile.Parse(options.SolutionFullPath);

            UpdateSolutionFile(project, slnFile, options.Preview);
            return(true);
        }
Ejemplo n.º 15
0
    private static void HandleSolution(string solutionFile, Parameters parameters)
    {
        var solution     = SolutionFile.Parse(solutionFile);
        var solutionName = Path.GetFileName(solutionFile);

        Console.Out.WriteLine($"Working with '{parameters.SolutionConfiguration}' solution configuration.");

        var projects = FilterProjectsByConfiguration(solution.ProjectsInOrder, parameters.SolutionConfiguration)
                       .ToArray();

        if (!projects.Any())
        {
            Console.Out.WriteLine($"No projects found in solution {solutionName}.");
            return;
        }

        Console.Out.WriteLine(
            $"Found projects in solution {solutionName}: {Environment.NewLine}\t{string.Join(Environment.NewLine + "\t", projects.Select(project => project.AbsolutePath))}");
        Console.Out.WriteLine();

        var allProjectsInSolution = projects
                                    .Select(p => p.ProjectName)
                                    .ToHashSet(StringComparer.OrdinalIgnoreCase);

        foreach (var solutionProject in projects)
        {
            HandleProject(solutionProject, allProjectsInSolution, parameters);
        }
    }
Ejemplo n.º 16
0
        public Solution(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException($"{nameof(filePath)} does not match valid file path.", filePath);
            }

            SolutionFile msSolution;

            try
            {
                msSolution = SolutionFile.Parse(filePath);
            }
            catch (Exception e)
            {
                throw new ArgumentException($"'{nameof(filePath)}' could not be parsed as solution.", nameof(filePath), e);
            }

            var projectFilePaths    = new HashSet <string>();
            var rawProjectFilePaths = new HashSet <string>();

            foreach (var project in msSolution.ProjectsInOrder)
            {
                projectFilePaths.Add(project.AbsolutePath.Replace('\\', '/'));
                rawProjectFilePaths.Add(project.RelativePath);
            }

            Name                = Path.GetFileNameWithoutExtension(filePath);
            FilePath            = filePath.Replace('\\', '/');
            ProjectFilePaths    = projectFilePaths;
            RawProjectFilePaths = rawProjectFilePaths;

            _Projects = new HashSet <IProject>();
        }
        private async Task AddProjectsToSolutionAsync(ReferenceSwitcherConfiguration configuration, IConsoleHost host)
        {
            var solution          = SolutionFile.Parse(configuration.ActualSolution);
            var projects          = new List <string>();
            var solutionFolderArg = "";

            foreach (var mapping in configuration.Mappings)
            {
                foreach (var path in mapping.Value)
                {
                    if (solution.ProjectsInOrder.All(p => p.ProjectName != mapping.Key)) // check that it's not already in the solution
                    {
                        projects.Add("\"" + configuration.GetActualPath(path) + "\"");
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(configuration.SolutionFolder))
            {
                solutionFolderArg = $" --solution-folder {configuration.SolutionFolder}";
            }
            if (projects.Any())
            {
                await ExecuteCommandAsync(
                    "dotnet", "sln \"" + configuration.ActualSolution + "\" add " + string.Join(" ", projects) + solutionFolderArg, host);
            }
        }
Ejemplo n.º 18
0
        public static SolutionItem Parse(string solutionFilename)
        {
            SolutionFile solutionFile = SolutionFile.Parse(solutionFilename);

            List <ProjectItem> projects = solutionFile.ProjectsInOrder
                                          .Select(project => ProjectParser.Parse(project.AbsolutePath, project.ProjectGuid)).ToList();

            Dictionary <ProjectItem, List <string> > projectContainer = new Dictionary <ProjectItem, List <string> >();

            foreach (ProjectInSolution projectInSolution in solutionFile.ProjectsInOrder)
            {
                ProjectItem project =
                    ProjectParser.Parse(projectInSolution.AbsolutePath, projectInSolution.ProjectGuid);

                List <string> dependencies = projectInSolution.Dependencies.ToList();

                foreach (ProjectReferenceItem projectReference in project.ProjectReferences)
                {
                    ProjectInSolution referredProject = solutionFile.ProjectsInOrder.FirstOrDefault(p =>
                                                                                                    Path.Combine(p.AbsolutePath, p.ProjectName).ToLowerInvariant().Equals(Path
                                                                                                                                                                          .Combine(projectReference.AbsolutePath, projectReference.Name).ToLowerInvariant()));

                    if (referredProject != null && !dependencies.Contains(referredProject.ProjectGuid))
                    {
                        dependencies.Add(referredProject.ProjectGuid);
                    }
                }

                projectContainer.Add(project, dependencies);
            }

            return(new SolutionItem(ResolveBuildOrder(projectContainer)));
        }
Ejemplo n.º 19
0
        private static IEnumerable <FileInfo> EnumerateProjectsCore(FileInfo solutionFile)
        {
            var solution = SolutionFile.Parse(solutionFile.FullName);

            foreach (var project in solution.ProjectsInOrder)
            {
                if (project.ProjectType != SolutionProjectType.KnownToBeMSBuildFormat)
                {
                    continue;
                }

                var extension = Path.GetExtension(project.AbsolutePath).ToLower();
                switch (extension)
                {
                case ".csproj":
                case ".fsproj":
                    break;

                default:
                    continue;
                }

                yield return(new FileInfo(project.AbsolutePath.Replace('\\', '/')));
            }
        }
Ejemplo n.º 20
0
        private void OnExecute()
        {
            var fullSolutionPath = Path.GetFullPath(SolutionPath);
            var fullOutputPath   = Path.GetFullPath(OutputPath);
            var solution         = SolutionFile.Parse(fullSolutionPath);
            var projects         = solution.ProjectsInOrder;

            var filterPath = fullOutputPath;

            var filter = new Solution()
            {
                Path     = GetRelativePath(OutputPath, SolutionPath),
                Projects = projects.Where(p => IncludedProjects
                                          .Any(x => p.ProjectName.Contains(x)))
                           .Select(p => p.RelativePath).ToList()
            };
            var root = new Root(filter);

            var options = new JsonSerializerOptions
            {
                WriteIndented = true,
            };

            using var fs = File.Create(filterPath);

            JsonSerializer.SerializeAsync(fs, root, options).Wait();
        }
Ejemplo n.º 21
0
        private static async Task <Application> CreateApplicationForSolutionAsync(OutputContext output, FileInfo solutionFile)
        {
            // Solution workflow:
            //
            //  1. If there's an 'Opulence.csx' - use that that to initialize the set of services.
            //  2. If there's not an 'Opulence.csx' then grovel all of the projects in the solution looking
            //     for executable projects.

            SolutionFile solution;

            try
            {
                solution = SolutionFile.Parse(solutionFile.FullName);
            }
            catch (Exception ex)
            {
                throw new CommandException($"Parsing solution file '{solutionFile.FullName}' failed.", ex);
            }

            var application = await ScriptRunner.RunCustomizationScriptAsync(output, solutionFile, solution);

            if (application != null)
            {
                return(application);
            }

            return(await InferApplicationForSolution(output, solutionFile, solution));
        }
        private static Dictionary <string, IEnumerable <string> > GetProjectToSolutionFolderMap(string solutionFilePath)
        {
            if (!solutionFilePath.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var solutionFile = SolutionFile.Parse(solutionFilePath);

            var result = new Dictionary <string, IEnumerable <string> >(StringComparer.OrdinalIgnoreCase);

            foreach (var project in solutionFile.ProjectsInOrder)
            {
                if (project.ProjectType == SolutionProjectType.SolutionFolder)
                {
                    continue;
                }

                var path = GetAbsoluteFilePath(project);
                var parentFolderChain = GetParentFolderChain(solutionFile, project);

                result.Add(path, parentFolderChain);
            }

            return(result);
        }
Ejemplo n.º 23
0
    private static void HandleSolution(string solutionFile, Parameters parameters)
    {
        var solution     = SolutionFile.Parse(solutionFile);
        var solutionName = Path.GetFileName(solutionFile);

        Console.Out.WriteLine($"Working with '{parameters.SolutionConfiguration}' solution configuration.");

        var projects = FilterProjectsByConfiguration(solution.ProjectsInOrder, parameters.SolutionConfiguration)
                       .ToArray();

        if (!projects.Any())
        {
            Console.Out.WriteLine($"No projects found in solution {solutionName}.");
            return;
        }

        Console.Out.WriteLine(
            $"Found projects in solution {solutionName}: {Environment.NewLine}\t{string.Join(Environment.NewLine + "\t", projects.Select(project => project.AbsolutePath))}");
        Console.Out.WriteLine();


        var graph = new Dictionary <string, string[]>();

        foreach (var solutionProject in projects)
        {
            graph[solutionProject.AbsolutePath] = GetDependencyProjects(solutionProject)
                                                  .Select(x => Path.GetFullPath(Path.Combine(Path.GetDirectoryName(solutionProject.AbsolutePath), x)))
                                                  .ToArray();
        }

        var sorted = SortTopological(graph);

        Console.Out.WriteLine($"Projects in topological sorted order:\r\n\t{string.Join("\r\n\t", sorted)}");
        File.WriteAllLines(parameters.OutputFile, sorted);
    }
Ejemplo n.º 24
0
 public GGPSolutionParser(ComponentsFolder componentsFolder, IBuildCustomizationProvider customizationProvider)
 {
     _componentsFolder      = componentsFolder;
     _solutionFile          = SolutionFile.Parse(GetSolutionFile(componentsFolder));
     _customizationProvider = customizationProvider;
     LoadComponents();
 }
Ejemplo n.º 25
0
        public void Merge_AdjustProjectRelativePath_2()
        {
            var baseSln    = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Unity.sln", @"
Microsoft Visual Studio Solution File, Format Version 12.00
Global
EndGlobal
".Trim());
            var overlaySln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Server.sln", @"
Microsoft Visual Studio Solution File, Format Version 12.00
Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Nantoka.Server"", ""Nantoka.Server\Nantoka.Server.csproj"", ""{053476FC-B8B2-4A14-AED2-3733DFD5DFC3}""
EndProject
Global
EndGlobal
".Trim());

            var mergedSolutionFile = SlnMerge.Merge(baseSln, overlaySln, new SlnMergeSettings(), SlnMergeNullLogger.Instance);
            var content            = mergedSolutionFile.ToFileContent();

            Assert.Equal(@"..\Nantoka.Server\Nantoka.Server.csproj".Replace('\\', Path.DirectorySeparatorChar), mergedSolutionFile.Projects.First().Value.Path);
            Assert.Equal(@"
Microsoft Visual Studio Solution File, Format Version 12.00
Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""Nantoka.Server"", ""..\Nantoka.Server\Nantoka.Server.csproj"", ""{053476FC-B8B2-4A14-AED2-3733DFD5DFC3}""
EndProject
Global
EndGlobal
".Trim(), content.Trim());
        }
Ejemplo n.º 26
0
        public Solution(Autobuilder builder, string path, bool allowProject) : base(builder, path)
        {
            try
            {
                solution = SolutionFile.Parse(FullPath);
            }
            catch (Exception ex) when (ex is InvalidProjectFileException || ex is FileNotFoundException)
            {
                // We allow specifying projects as solutions in lgtm.yml, so model
                // that scenario as a solution with just that one project
                if (allowProject)
                {
                    includedProjects = new[] { new Project(builder, path) };
                    return;
                }

                builder.Log(Severity.Info, $"Unable to read solution file {path}.");
                includedProjects = new Project[0];
                return;
            }

            includedProjects =
                solution.ProjectsInOrder.
                Where(p => p.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat).
                Select(p => builder.Actions.PathCombine(DirectoryName, builder.Actions.PathCombine(p.RelativePath.Split('\\', StringSplitOptions.RemoveEmptyEntries)))).
                Select(p => new Project(builder, p)).
                ToArray();
        }
Ejemplo n.º 27
0
        private void ValidateProjectInSolution(Action <SlnProject, ProjectInSolution> customValidator, SlnProject[] projects, bool folders)
        {
            string solutionFilePath = GetTempFileName();

            SlnFile slnFile = new SlnFile();

            slnFile.AddProjects(projects);
            slnFile.Save(solutionFilePath, folders);

            SolutionFile solutionFile = SolutionFile.Parse(solutionFilePath);

            foreach (SlnProject slnProject in projects)
            {
                solutionFile.ProjectsByGuid.ContainsKey(slnProject.ProjectGuid.ToSolutionString()).ShouldBeTrue();

                ProjectInSolution projectInSolution = solutionFile.ProjectsByGuid[slnProject.ProjectGuid.ToSolutionString()];

                projectInSolution.AbsolutePath.ShouldBe(slnProject.FullPath);
                projectInSolution.ProjectGuid.ShouldBe(slnProject.ProjectGuid.ToSolutionString());
                projectInSolution.ProjectName.ShouldBe(slnProject.Name);

                IEnumerable <string> expected = slnProject.Configurations.SelectMany(configuration => slnProject.Platforms, (configuration, platform) => $"{configuration}|{platform}");
                IEnumerable <string> actual   = projectInSolution.ProjectConfigurations.Where(i => i.Value.IncludeInBuild).Select(i => i.Key);

                expected.ShouldBe(actual, ignoreOrder: true);

                customValidator?.Invoke(slnProject, projectInSolution);
            }
        }
Ejemplo n.º 28
0
        private void SolutionFilesSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = false;
            dialog.Filter      = "Solution File|*sln";

            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string              fileName = dialog.FileName;
                SolutionFile        solution = SolutionFile.Parse(fileName);
                SolutionTreeContent solutionTree;
                if (ContainsWindow(_solutionTreeGuid))
                {
                    solutionTree = GetWindow <SolutionTreeContent>(_solutionTreeGuid).Value;
                    solutionTree.LoadSolution(solution, fileName);
                }
                else
                {
                    solutionTree = new SolutionTreeContent(this);
                    solutionTree.LoadSolution(solution, fileName);

                    _solutionTreeGuid = solutionTree.WindowGuid;

                    AddWindow(solutionTree);
                }
            }
        }
Ejemplo n.º 29
0
        private List <ProjectDetails> GetProjects(string pathToSolution)
        {
            var solution = SolutionFile.Parse(pathToSolution);

            var projects = solution.ProjectsInOrder.Select(p =>
            {
                if (p.ProjectType != SolutionProjectType.KnownToBeMSBuildFormat && p.ProjectType != SolutionProjectType.WebProject)
                {
                    return(null);
                }

                var projectParser = new ProjectFileParser(p.AbsolutePath);

                return(new ProjectDetails
                {
                    ProjectName = p.ProjectName,
                    ProjectFilePath = p.AbsolutePath,
                    ProjectGuid = p.ProjectGuid,
                    TargetFrameworks = projectParser.GetTargetFrameworks().ConvertAll(tfm =>
                    {
                        var framework = NuGetFramework.Parse(tfm);
                        return string.Format("{0} {1}", framework.Framework, NuGetVersion.Parse(framework.Version.ToString()).ToNormalizedString());
                    }),
                    PackageReferences = projectParser.GetPackageReferences()
                });
            }).Where(p => p != null).ToList();

            return(projects);
        }
Ejemplo n.º 30
0
        private void ValidateProjectInSolution(Action <SlnProject, ProjectInSolution> customValidator, SlnProject[] projects, bool folders)
        {
            string solutionFilePath = GetTempFileName();

            SlnFile slnFile = new SlnFile();

            slnFile.AddProjects(projects);
            slnFile.Save(solutionFilePath, folders);

            SolutionFile solutionFile = SolutionFile.Parse(solutionFilePath);

            foreach (SlnProject slnProject in projects)
            {
                solutionFile.ProjectsByGuid.ContainsKey(slnProject.ProjectGuid.ToSolutionString()).ShouldBeTrue();

                ProjectInSolution projectInSolution = solutionFile.ProjectsByGuid[slnProject.ProjectGuid.ToSolutionString()];

                projectInSolution.AbsolutePath.ShouldBe(slnProject.FullPath);
                projectInSolution.ProjectGuid.ShouldBe(slnProject.ProjectGuid.ToSolutionString());
                projectInSolution.ProjectName.ShouldBe(slnProject.Name);

                IEnumerable <string> configurationPlatforms = from configuration in slnProject.Configurations from platform in slnProject.Platforms select $"{configuration}|{platform}";

                configurationPlatforms.ShouldBe(projectInSolution.ProjectConfigurations.Keys, ignoreOrder: true);

                customValidator?.Invoke(slnProject, projectInSolution);
            }
        }