示例#1
0
        private int OnCrossrefClear(CommandLineApplication cmd, CommandArgument argPath)
        {
            var paths = new[] { argPath.Value }
            .Concat(cmd.RemainingArguments)
            .Select(path => Path.GetFullPath(path))
            .ToArray();

            Console.WriteLine($"Executing Crossref Clear");

            var operations = new WorkspaceOperations();
            var workspace  = new DotnetWorkspace();

            foreach (var path in paths)
            {
                operations.FindAndLoadSolutions(workspace, path);
            }

            foreach (var solution in workspace.Solutions)
            {
                solution.GlobalJson.ClearAddedProjects();
            }

            foreach (var solution in workspace.Solutions)
            {
                solution.GlobalJson.Save();
            }

            return(0);
        }
示例#2
0
        private int OnCrossrefAdd(
            CommandLineApplication cmd,
            CommandArgument argPath)
        {
            var paths = new[] { argPath.Value }
                .Concat(cmd.RemainingArguments)
                .Select(path => Path.GetFullPath(path))
                .ToArray();

            Console.WriteLine($"Executing Crossref Add");

            var operations = new WorkspaceOperations();
            var workspace = new DotnetWorkspace();

            foreach (var path in paths)
            {
                operations.FindAndLoadSolutions(workspace, path);
            }
            operations.FindAndLoadProjects2(workspace);
            operations.FindProjectToProjectDependencies(workspace);

            foreach (var solution in workspace.Solutions)
            {
                var allProject = solution.Projects.Select(p => Tuple.Create(p, p, p));

                var allProject2Project = SelectRecursive(0, allProject);

                var allProject2ProjectLocations = allProject2Project
                    .Where(tuple => tuple.Item1.ProjectJson.ParentPath != tuple.Item3.ProjectJson.ParentPath)
                    .GroupBy(tuple => MakeRelativePath(solution.GlobalJson.FilePath, tuple.Item3.ProjectJson.ParentPath).Replace("\\", "/"))
                    .ToArray();

                var neededLocations = new List<string>();

            //                Console.WriteLine($"  {solution.GlobalJson.FolderPath}");
                foreach (var project2ProjectLocation in allProject2ProjectLocations)
                {
                    neededLocations.Add(project2ProjectLocation.Key);
              //                  Console.WriteLine($"    {project2ProjectLocation.Key}");
                    foreach (var dependencyName in project2ProjectLocation.Select(x => x.Item3.Name).Distinct())
                    {
            //                    Console.WriteLine($"      {dependencyName}");
                    }
                }

                foreach (var neededLocation in neededLocations)
                {
                    if (!solution.GlobalJson.ProjectFolders.Any(pf =>
                        string.Equals(pf.Path, neededLocation, StringComparison.OrdinalIgnoreCase)))
                    {
                        solution.GlobalJson.AddProjectFolder(neededLocation);
                    }
                }
            }

            foreach (var solution in workspace.Solutions)
            {
                solution.GlobalJson.Save();
            }

            using (var batch = File.CreateText("restore-all.cmd"))
            {
                foreach (var p in workspace.Projects)
                {
                    batch.WriteLine($"call dnu restore {p.ProjectJson.FolderPath}");
                }
            }
            return 0;
        }
示例#3
0
        private int OnCrossrefClear(CommandLineApplication cmd, CommandArgument argPath)
        {
            var paths = new[] { argPath.Value }
                .Concat(cmd.RemainingArguments)
                .Select(path => Path.GetFullPath(path))
                .ToArray();

            Console.WriteLine($"Executing Crossref Clear");

            var operations = new WorkspaceOperations();
            var workspace = new DotnetWorkspace();

            foreach (var path in paths)
            {
                operations.FindAndLoadSolutions(workspace, path);
            }

            foreach (var solution in workspace.Solutions)
            {
                solution.GlobalJson.ClearAddedProjects();
            }

            foreach (var solution in workspace.Solutions)
            {
                solution.GlobalJson.Save();
            }

            return 0;
        }
示例#4
0
        private int OnCrossrefAdd(
            CommandLineApplication cmd,
            CommandArgument argPath)
        {
            var paths = new[] { argPath.Value }
            .Concat(cmd.RemainingArguments)
            .Select(path => Path.GetFullPath(path))
            .ToArray();

            Console.WriteLine($"Executing Crossref Add");

            var operations = new WorkspaceOperations();
            var workspace  = new DotnetWorkspace();

            foreach (var path in paths)
            {
                operations.FindAndLoadSolutions(workspace, path);
            }
            operations.FindAndLoadProjects2(workspace);
            operations.FindProjectToProjectDependencies(workspace);

            foreach (var solution in workspace.Solutions)
            {
                var allProject = solution.Projects.Select(p => Tuple.Create(p, p, p));

                var allProject2Project = SelectRecursive(0, allProject);

                var allProject2ProjectLocations = allProject2Project
                                                  .Where(tuple => tuple.Item1.ProjectJson.ParentPath != tuple.Item3.ProjectJson.ParentPath)
                                                  .GroupBy(tuple => MakeRelativePath(solution.GlobalJson.FilePath, tuple.Item3.ProjectJson.ParentPath).Replace("\\", "/"))
                                                  .ToArray();

                var neededLocations = new List <string>();

//                Console.WriteLine($"  {solution.GlobalJson.FolderPath}");
                foreach (var project2ProjectLocation in allProject2ProjectLocations)
                {
                    neededLocations.Add(project2ProjectLocation.Key);
                    //                  Console.WriteLine($"    {project2ProjectLocation.Key}");
                    foreach (var dependencyName in project2ProjectLocation.Select(x => x.Item3.Name).Distinct())
                    {
                        //                    Console.WriteLine($"      {dependencyName}");
                    }
                }

                foreach (var neededLocation in neededLocations)
                {
                    if (!solution.GlobalJson.ProjectFolders.Any(pf =>
                                                                string.Equals(pf.Path, neededLocation, StringComparison.OrdinalIgnoreCase)))
                    {
                        solution.GlobalJson.AddProjectFolder(neededLocation);
                    }
                }
            }

            foreach (var solution in workspace.Solutions)
            {
                solution.GlobalJson.Save();
            }

            using (var batch = File.CreateText("restore-all.cmd"))
            {
                foreach (var p in workspace.Projects)
                {
                    batch.WriteLine($"call dnu restore {p.ProjectJson.FolderPath}");
                }
            }
            return(0);
        }