Ejemplo n.º 1
0
        public void Execute(string basePath, string solutionFile, string pattern, string target)
        {
            var solution = SolutionFile.FromFile(Path.Combine(basePath, solutionFile));
            var regex    = new Regex(pattern);

            var projects = solution.Projects.Where(item => regex.IsMatch(item.ProjectName))
                           .ToList();

            if (!string.IsNullOrEmpty(target))
            {
                foreach (var project in projects)
                {
                    // If project type is folder, remove all child folders
                    if (project.ProjectTypeGuid == MsBuildExtensions.solutionFolderGuid)
                    {
                        foreach (var childProject in project.Childs.ToList())
                        {
                            if (solution.Projects.Remove(childProject))
                            {
                                Logger.Info($"Removing child project {project.ProjectName} from solution {solutionFile}");
                            }
                        }
                    }

                    if (solution.Projects.Remove(project))
                    {
                        Logger.Info($"Removing project {project.ProjectName} from solution {solutionFile}");
                    }
                }

                solution.SaveAs(Path.Combine(basePath, target));
            }
        }
Ejemplo n.º 2
0
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            lock (r_watcher)
            {
                try
                {
                    WaitForFileToBeReleased(e.FullPath);

                    var newFilteredSolution = SolutionFile.FromFile(m_filteredSolution.SolutionFullPath);
                    var difference          = newFilteredSolution.CompareTo(m_filteredSolution);
                    if (difference != null)
                    {
                        difference.Remove(diff => diff.Identifier.Name.Contains("SccProjectTopLevelParentUniqueName"));
                        if (difference.Subdifferences.Count > 0)
                        {
                            if (r_acceptDifferencesHandler(difference))
                            {
                                var newOriginalSolution = SolutionFile.FromElement((NodeElement)r_filterFile.SourceSolution.ToElement().Apply(difference));
                                newOriginalSolution.Save();
                                m_filteredSolution = newFilteredSolution;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // TODO Better handling of error, this assembly shouldn't display UI by itself
                    MessageBox.Show(ex.ToString(), "OnChanged handler");
                }
            }
        }
Ejemplo n.º 3
0
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            lock (r_watcher)
            {
                try
                {
                    WaitForFileToBeReleased(e.FullPath);

                    var newFilteredSolution = SolutionFile.FromFile(m_filteredSolution.SolutionFullPath);
                    var difference          = newFilteredSolution.CompareTo(m_filteredSolution);
                    if (difference != null)
                    {
                        difference.Remove(diff => diff.Identifier.Name.Contains("SccProjectTopLevelParentUniqueName"));
                        if (difference.Subdifferences.Count > 0)
                        {
                            if (r_acceptDifferencesHandler(difference))
                            {
                                var newOriginalSolution = SolutionFile.FromElement((NodeElement)r_filterFile.SourceSolution.ToElement().Apply(difference));
                                newOriginalSolution.Save();
                                m_filteredSolution = newFilteredSolution;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("OnChanged handler: " + ex.ToString());
                }
            }
        }
Ejemplo n.º 4
0
        private IEnumerable <MismatchedGuid> GetBadProjectRefGuids()
        {
            var solutionProjects = SolutionFile.FromFile(RoslynProject.Solution.FilePath).Projects;

            return(MsBuildProject.GetProjectReferences()
                   .Where(r => !r.EqualByGuid(GetSolutionProjectFromProjectReference(r, solutionProjects)))
                   .Select(r => new MismatchedGuid(r.GetProjectGuid(), r.GetProjectName(), "Project Reference")));
        }
Ejemplo n.º 5
0
    public static void ProcessReferences(string solutionFullPath)
    {
        var sln      = SolutionFile.FromFile(solutionFullPath);
        var projList = sln.Projects;

        foreach (var p in projList)
        {
            string fileNath = p.FullPath;
            Console.WriteLine(fileNath);
            var cslib = new ProjectAssemblyCSharp();
            cslib.Load(fileNath);
            foreach (var configuration in cslib.Configurations)
            {
                Console.WriteLine($"{configuration.Name} -> { configuration.GetAssemblyName()}");
            }
        }
    }
Ejemplo n.º 6
0
        private void OpenExecute()
        {
            var dlg = new OpenFileDialog();

            dlg.Filter = "Visual Studio Solution (sln)|*.sln";
            if (dlg.ShowDialog() == true)
            {
                try
                {
                    CurrentSolution = SolutionFile.FromFile(dlg.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    CurrentSolution = null;
                }
            }
        }
Ejemplo n.º 7
0
    public void AddProject(string newProjectName)
    {
        var baseSln = SolutionFile.FromFile(_solutionPath);

        var templateProject = GetTemplateProject(baseSln.Projects);

        baseSln.Projects.Add(new Project(
                                 container: baseSln,
                                 projectGuid: "{" + Guid.NewGuid().ToString().ToUpper() + "}",
                                 projectTypeGuid: templateProject.ProjectTypeGuid,
                                 projectName: newProjectName,
                                 relativePath: templateProject.RelativePath.Replace(templateProject.ProjectName, newProjectName),
                                 parentFolderGuid: templateProject.ParentFolderGuid,
                                 projectSections: templateProject.ProjectSections,
                                 versionControlLines: SetVersionControlLines(templateProject, templateProject.ProjectName, newProjectName),
                                 projectConfigurationPlatformsLines: templateProject.ProjectConfigurationPlatformsLines));

        baseSln.Save();
    }
Ejemplo n.º 8
0
    public static void RemoveProject(string solutionFullPath, string projectName)
    {
        Console.WriteLine($"Removing {projectName} from {solutionFullPath}");
        var listToRemove = new List <Project>();
        var sln          = SolutionFile.FromFile(solutionFullPath);
        var projList     = sln.Projects;

        foreach (var p in projList)
        {
            if (string.Compare(p.ProjectName, projectName) == 0)
            {
                listToRemove.Add(p);
            }
        }
        foreach (var r in listToRemove)
        {
            sln.Projects.Remove(r);
        }
        sln.Save();         // or .SaveAs("NewName.sln");
    }
Ejemplo n.º 9
0
 public static void Main(string[] args)
 {
     try
     {
         if (args.Length < 2)
         {
             Console.WriteLine("{0}", "usage: API-learning {filename} {guid}");
             Environment.Exit(ReturnCodes.NO_ENOUGH_ARGUMENTS);
         }
         var filename   = args [1];
         var project_id = args [2];
         var sol        = SolutionFile.FromFile(filename);
         sol.Projects.Remove(project_id);
         sol.SaveAs(filename + ".new");
         Environment.Exit(ReturnCodes.SUCCESS);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         Environment.Exit(ReturnCodes.EXCEPTION);
     }
 }
        static void ProcessDirectory(string path, ProcessingContext ctx)
        {
            ctx.Writer.WriteLine("Processing directory: " + path);
            ctx.Writer.Indent++;
            try
            {
                var listOfFiles = Directory.EnumerateFiles(path, "*.sln", SearchOption.AllDirectories);
                foreach (string file in listOfFiles)
                {
                    try
                    {
                        var sln = SolutionFile.FromFile(file);
                        ProcessSolution(sln, ctx);
                    }
                    catch (Exception ex)
                    {
                        ctx.Writer.Write("Error while processing solution: " + ex.ToString());
                    }
                }
            }
            finally
            {
                ctx.Writer.Indent--;
            }
            ctx.Writer.WriteLine("Summary:");
            var libs = new SortedList <string, bool>();

            foreach (var item in ctx.Count)
            {
                libs.Add($"{item.Value} {item.Key}", false);
            }
            foreach (var item in libs.Keys)
            {
                ctx.Writer.WriteLine($"{item}");
            }
        }
Ejemplo n.º 11
0
        public override void Run(string[] args, MessageBoxErrorReporter reporter)
        {
            var parsedArguments = new Arguments();

            reporter.CommandUsage = Parser.ArgumentsUsage(parsedArguments.GetType());

            if (Parser.ParseArguments(args, parsedArguments, reporter.Handler))
            {
                if (parsedArguments.Solutions.Length < 2)
                {
                    reporter.Handler("Two solution files should be provided, in order:\n   Old.sln\n   New.sln");
                    return;
                }

                var oldSolution = CheckForWarnings(SolutionFile.FromFile(parsedArguments.Solutions[0]), parsedArguments.IgnoreWarning);
                var newSolution = CheckForWarnings(SolutionFile.FromFile(parsedArguments.Solutions[1]), parsedArguments.IgnoreWarning);
                var difference  = newSolution.CompareTo(oldSolution)
                                  ?? new NodeDifference(new ElementIdentifier("SolutionFile"), OperationOnParent.Modified, null);
                using (var form = new CompareSolutionsForm(difference))
                {
                    form.ShowDialog();
                }
            }
        }
Ejemplo n.º 12
0
        public override void Run(string[] args, MessageBoxErrorReporter reporter)
        {
            var parsedArguments = new Arguments();

            reporter.CommandUsage = Parser.ArgumentsUsage(parsedArguments.GetType());

            if (Parser.ParseArguments(args, parsedArguments, reporter.Handler))
            {
                if (parsedArguments.Solutions.Length < 4)
                {
                    reporter.Handler("Four solution files should be provided, in order:\n   SourceBranch.sln\n   DestinationBranch.sln\n   CommonAncestror.sln\n   Result.sln");
                    return;
                }

                var solutionInSourceBranch      = CheckForWarnings(SolutionFile.FromFile(parsedArguments.Solutions[0]), parsedArguments.IgnoreWarning);
                var solutionInDestinationBranch = CheckForWarnings(SolutionFile.FromFile(parsedArguments.Solutions[1]), parsedArguments.IgnoreWarning);
                var commonAncestrorSolution     = CheckForWarnings(SolutionFile.FromFile(parsedArguments.Solutions[2]), parsedArguments.IgnoreWarning);
                var mergedSolutionName          = parsedArguments.Solutions[3];

                var elementInSourceBranch      = solutionInSourceBranch.ToElement();
                var elementInDestinationBranch = solutionInDestinationBranch.ToElement();
                var commonAncestrorElement     = commonAncestrorSolution.ToElement();

                NodeDifference differenceInSourceBranch;
                NodeDifference differenceInDestinationBranch;
                var            conflict = Conflict.Merge(
                    commonAncestrorElement,
                    elementInSourceBranch,
                    elementInDestinationBranch,
                    out differenceInSourceBranch,
                    out differenceInDestinationBranch);

                using (var form = new MergeSolutionsForm(
                           differenceInSourceBranch,
                           differenceInDestinationBranch,
                           conflict,
                           delegate(ConflictContext context, Difference differenceTypeInSourceBranch, Difference differenceTypeInDestinationBranch)
                {
                    var resolverForm = new OperationTypeConflictResolverForm(
                        context,
                        differenceTypeInSourceBranch,
                        differenceTypeInDestinationBranch);
                    resolverForm.ShowDialog();
                    return(resolverForm.Result);
                },
                           delegate(ConflictContext context, string valueInSourceBranch, string valueInDestinationBranch)
                {
                    var resolverForm = new ValueConflictResolverForm(
                        context,
                        valueInSourceBranch,
                        valueInDestinationBranch);
                    resolverForm.ShowDialog();
                    return(resolverForm.Result);
                }))
                {
                    if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        var mergedElement  = (NodeElement)commonAncestrorElement.Apply(form.Result);
                        var mergedSolution = SolutionFile.FromElement(mergedElement);
                        mergedSolution.SaveAs(mergedSolutionName);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void Execute()
        {
            // source and dest dir
            string srcDir = Path.Combine(
                bcl.myEnv.BOSSS_SRC.FullName,
                Path.Combine("L4-application", "BoSSSTemplateProject"));

            string destDir;

            if (Path.IsPathRooted(m_CreationPath))
            {
                destDir = m_CreationPath;
            }
            else
            {
                destDir = Path.Combine(Directory.GetCurrentDirectory(), m_CreationPath);
            }
            destDir = Path.Combine(destDir, m_newName);
            Console.WriteLine("creating in :" + destDir);


            DirectoryInfo _srcDir  = new DirectoryInfo(srcDir);
            DirectoryInfo _destDir = new DirectoryInfo(destDir);

            // create destination dir
            if (_destDir.Exists)
            {
                throw new ApplicationException("project directory '" + destDir + "' already exists.");
            }
            _destDir.Create();

            // copy files
            // ==========
            File.Copy(Path.Combine(srcDir, "TemplateMain.cs"), Path.Combine(destDir, m_newName + "Main.cs"));
            File.Copy(Path.Combine(srcDir, "app.config"), Path.Combine(destDir, "app.config"));
            Directory.CreateDirectory(Path.Combine(destDir, "Properties"));
            File.Copy(Path.Combine(srcDir, Path.Combine("Properties", "AssemblyInfo.cs")), Path.Combine(destDir, Path.Combine("Properties", "AssemblyInfo.cs")));

            // project file
            // ============
            Guid newProjGuid = Guid.NewGuid();
            {
                XmlDocument projFile = new XmlDocument();
                projFile.Load(Path.Combine(srcDir, "BoSSSTemplateProject.csproj"));
                XmlNamespaceManager scheissDing = new XmlNamespaceManager(projFile.NameTable);
                scheissDing.AddNamespace("haß", "http://schemas.microsoft.com/developer/msbuild/2003");

                // guid
                XmlNode proj_guid = projFile.SelectSingleNode("/haß:Project/haß:PropertyGroup/haß:ProjectGuid", scheissDing);
                //Console.WriteLine(proj_guid.InnerText);
                proj_guid.InnerText = newProjGuid.ToString("B");
                //Console.WriteLine(proj_guid.InnerText);

                // RootNamespace
                XmlNode root_Namesp = projFile.SelectSingleNode("/haß:Project/haß:PropertyGroup/haß:RootNamespace", scheissDing);
                root_Namesp.InnerText = m_newName;

                // AssemblyName
                XmlNode AssemblyName = projFile.SelectSingleNode("/haß:Project/haß:PropertyGroup/haß:AssemblyName", scheissDing);
                AssemblyName.InnerText = m_newName;

                // MainFile
                var CsFiles = projFile.SelectNodes("/haß:Project/haß:ItemGroup/haß:Compile/@Include", scheissDing);
                foreach (var f in CsFiles)
                {
                    XmlAttribute att = f as XmlAttribute;
                    if (att.Value == "TemplateMain.cs")
                    {
                        att.Value = m_newName + "Main.cs";
                    }
                }

                // ProjectReferences
                var ProjRefs = projFile.SelectNodes("/haß:Project/haß:ItemGroup/haß:ProjectReference/@Include", scheissDing);
                foreach (var f in ProjRefs)
                {
                    XmlAttribute att = f as XmlAttribute;

                    FileInfo item = new FileInfo(Path.Combine(srcDir, att.Value));
                    //Console.WriteLine(item.FullName + ", " + item.Exists);

                    string newPath = GetRelPath(item, _destDir);
                    //Console.WriteLine(item.FullName + ", " + File.Exists(newPath));
                    att.Value = newPath;
                }
                // References
                var Refs = projFile.SelectNodes("/haß:Project/haß:ItemGroup/haß:Reference/haß:HintPath", scheissDing);
                foreach (var f in Refs)
                {
                    var n = f as XmlNode;

                    FileInfo item = new FileInfo(Path.Combine(srcDir, n.InnerText));
                    //Console.WriteLine(item.FullName + ", " + item.Exists);

                    string newPath = GetRelPath(item, _destDir);
                    //Console.WriteLine(item.FullName + ", " + File.Exists(newPath));
                    n.InnerText = newPath;
                }

                // save
                projFile.Save(Path.Combine(destDir, m_newName + ".csproj"));
            }

            // solution file
            // =============
            {
                string newSolFile = Path.Combine(destDir, m_newName + "_WithDeps.sln");

                string templateSolFile;
                switch (m_VSversion)
                {
                case VisualStudioVersions.V15:
                    templateSolFile = "BoSSSTemplateProject_WithDeps.sln";
                    break;

                default:
                    throw new NotImplementedException();
                }
                templateSolFile = Path.Combine(srcDir, templateSolFile);

                var solution = SolutionFile.FromFile(templateSolFile);

                Project template = null;
                foreach (var proj in solution.Projects)
                {
                    if (proj.ProjectName == "BoSSSTemplateProject")
                    {
                        //proj.ProjectName = newName;
                        //proj.RelativePath = newName + ".csproj";
                        template = proj;
                    }
                    else
                    {
                        FileInfo prjFile = new FileInfo(proj.FullPath);
                        string   newPath = GetRelPath(prjFile, _destDir);
                        proj.RelativePath = newPath;
                    }
                }

                if (template == null)
                {
                    throw new ApplicationException("unable to find template project.");
                }

                var pNew = new Project(solution,
                                       newProjGuid.ToString("B"),
                                       template.ProjectGuid,
                                       m_newName,
                                       m_newName + ".csproj",
                                       template.ParentFolderGuid,
                                       template.ProjectSections,
                                       template.VersionControlLines,
                                       template.ProjectConfigurationPlatformsLines);

                solution.Projects.Remove(template);
                solution.Projects.Add(pNew);

                solution.SaveAs(newSolFile);
            }
        }