Пример #1
0
        public Solution GenerateSolution(string solutionFile, SolutionOptions options, bool testOnly = false)
        {
            this.NumberOfProjectsFound = 0;
            this.NumberOfProjectsSkipped = 0;
            this.NumberOfProjectsAdded = 0;
            this.NumberOfProjectsRemoved = 0;

            this._options = options;
            var rootDir = new DirectoryInfo(this._options.ProjectRootFolderPath);
            var includeFilter = new string[] { };
            if (!string.IsNullOrEmpty(this._options.IncludeFilter))
            {
                includeFilter = this._options.IncludeFilter.Split(';');
            }
            var excludeFilter = new string[] { };
            if (!string.IsNullOrEmpty(this._options.ExcludeFilter))
            {
                excludeFilter = this._options.ExcludeFilter.Split(';');
            }

            Solution oldSolution = null;
            if (File.Exists(solutionFile) && options.UpdateMode != SolutionUpdateMode.Replace)
            {
                var solutionReader = new SolutionReader();
                oldSolution = solutionReader.Read(solutionFile);
            }

            var projects = new List<SolutionProject>();
            ScanProjectDirectory(rootDir, projects, options.SolutionFileVersion, includeFilter, excludeFilter, this._options.Recursive);
            if (this._options.IncludeReferences)
            {
                ScanProjectReferences(projects, options.SolutionFileVersion, includeFilter, excludeFilter);
            }

            if (projects.Count > 0)
            {
                // Sort project files
                projects = (from p in projects orderby p.Name select p).ToList();

                var merger = new SolutionBuilder(options, _logger);
                var newSolution = merger.Build(oldSolution, projects);
                this.NumberOfProjectsAdded = merger.NumberOfProjectsAdded;
                this.NumberOfProjectsRemoved = merger.NumberOfProjectsRemoved;

                if (!testOnly)
                {
                    var solutionWriter = new SolutionWriter();
                    solutionWriter.Write(solutionFile, newSolution);
                }

                return newSolution;
            }
            else
            {
                return oldSolution;
            }
        }
Пример #2
0
        private static void GenSln(List<PrjInfo> thisLevel, int level)
        {
            var prjs = thisLevel.Where(item => !string.IsNullOrEmpty(item.PrjFilePath)).ToList();
            if (prjs.Count == 0) return;
            var generator = new SolutionGenerator(new ConsoleLogger());
            var slnOpt = new SolutionOptions();
            slnOpt.SolutionFolderPath = SlnPath + "buildSln" + level.ToString().PadLeft(3, '0') + ".sln";
            slnOpt.SolutionFileVersion = SolutionFileVersion.VisualStudio2012;
            slnOpt.ProjectRootFolderPath = prjs.FirstOrDefault().PrjFilePath;
            generator.GenerateSolution(slnOpt.SolutionFolderPath, slnOpt);

            prjs.RemoveAt(0);

            foreach (var prj in prjs)
            {
                slnOpt.UpdateMode = SolutionUpdateMode.Add;
                slnOpt.ProjectRootFolderPath = prj.PrjFilePath;
                generator.GenerateSolution(slnOpt.SolutionFolderPath, slnOpt);

            }




        }
Пример #3
0
 public SolutionBuilder(SolutionOptions options, ILogger logger)
 {
     _options = options;
     _logger  = logger;
 }
Пример #4
0
        public Solution GenerateSolution(string solutionFile, SolutionOptions options, bool testOnly = false)
        {
            this.NumberOfProjectsFound   = 0;
            this.NumberOfProjectsSkipped = 0;
            this.NumberOfProjectsAdded   = 0;
            this.NumberOfProjectsRemoved = 0;

            this._options = options;
            var rootDir       = new DirectoryInfo(this._options.ProjectRootFolderPath);
            var includeFilter = new string[] { };

            if (!string.IsNullOrEmpty(this._options.IncludeFilter))
            {
                includeFilter = this._options.IncludeFilter.Split(';');
            }
            var excludeFilter = new string[] { };

            if (!string.IsNullOrEmpty(this._options.ExcludeFilter))
            {
                excludeFilter = this._options.ExcludeFilter.Split(';');
            }

            Solution oldSolution = null;

            if (File.Exists(solutionFile) && options.UpdateMode != SolutionUpdateMode.Replace)
            {
                var solutionReader = new SolutionReader();
                oldSolution = solutionReader.Read(solutionFile);
            }

            var projects = new List <SolutionProject>();

            ScanProjectDirectory(rootDir, projects, options.SolutionFileVersion, includeFilter, excludeFilter, this._options.Recursive);
            if (this._options.IncludeReferences)
            {
                ScanProjectReferences(projects, options.SolutionFileVersion, includeFilter, excludeFilter);
            }

            if (projects.Count > 0)
            {
                // Sort project files
                projects = (from p in projects orderby p.Name select p).ToList();

                var merger      = new SolutionBuilder(options, _logger);
                var newSolution = merger.Build(oldSolution, projects);
                this.NumberOfProjectsAdded   = merger.NumberOfProjectsAdded;
                this.NumberOfProjectsRemoved = merger.NumberOfProjectsRemoved;

                if (!testOnly)
                {
                    var solutionWriter = new SolutionWriter();
                    solutionWriter.Write(solutionFile, newSolution);
                }

                return(newSolution);
            }
            else
            {
                return(oldSolution);
            }
        }
Пример #5
0
        private SolutionOptions CreateOptionsFromControls()
        {
            SolutionOptions options = new SolutionOptions
            {
                SolutionFolderPath = Path.GetDirectoryName(this.textSolutionFile.Text),
                ProjectRootFolderPath = this.textProjectRoot.Text,
                IncludeFilter = this.textIncludeFilter.Text,
                ExcludeFilter = this.textExcludeFilter.Text,
                Recursive = this.checkRecursive.Checked,
                IncludeReferences = this.checkIncludeReferences.Checked,
                ProjectTypes = ParseProjectTypesOption(this.textProjectTypes.Text),
                OverwriteReadOnlyFile = this.checkOverwriteReadonly.Checked,
                SolutionFileVersion = this.radioVersion2012.Checked ? 
                    SolutionFileVersion.VisualStudio2012 : this.radioVersion2010.Checked ? 
                    SolutionFileVersion.VisualStudio2010 : 
                    SolutionFileVersion.VisualStudio2008,
                SolutionFolderLevels = (int)this.numericSolutionFolderLevels.Value,
                FolderNamingMode = this.radioUseProjectNames.Checked ? 
                    SolutionFolderNamingMode.Project : this.radioUseAssemblyNames.Checked ? 
                    SolutionFolderNamingMode.Assembly : 
                    SolutionFolderNamingMode.MostQualified,
                CommonPrefixLevels = (int)this.numericCommonPrefixLevels.Value,
                CommonPrefixes = this.textCommonPrefixes.Text,

                UpdateMode = GetUpdateMode()
            };
            return options;
        }
Пример #6
0
        private void AssignOptionsToControls(SolutionOptions options)
        {
            this.textProjectRoot.Text = options.ProjectRootFolderPath;
            this.textIncludeFilter.Text = options.IncludeFilter;
            this.textExcludeFilter.Text = options.ExcludeFilter;
            this.checkRecursive.Checked = options.Recursive;
            this.checkIncludeReferences.Checked = options.IncludeReferences;
            this.textProjectTypes.Text = FormatProjectTypesOption(options.ProjectTypes);
            this.checkOverwriteReadonly.Checked = options.OverwriteReadOnlyFile;
            this.radioVersion2008.Checked = options.SolutionFileVersion == SolutionFileVersion.VisualStudio2008;
            this.radioVersion2010.Checked = options.SolutionFileVersion == SolutionFileVersion.VisualStudio2010;
            this.radioVersion2012.Checked = options.SolutionFileVersion == SolutionFileVersion.VisualStudio2012;
            this.numericSolutionFolderLevels.Value = options.SolutionFolderLevels;
            this.radioUseProjectNames.Checked = options.FolderNamingMode == SolutionFolderNamingMode.Project;
            this.radioUseAssemblyNames.Checked = options.FolderNamingMode == SolutionFolderNamingMode.Assembly;
            this.radioUseMostQualifiedNames.Checked = options.FolderNamingMode == SolutionFolderNamingMode.MostQualified;
            this.numericCommonPrefixLevels.Value = options.CommonPrefixLevels;
            this.radioCommonPrefixes.Checked = !string.IsNullOrEmpty(options.CommonPrefixes);
            this.textCommonPrefixes.Text = options.CommonPrefixes;

            SelectProjectTypes();
            SetUpdateMode(options.UpdateMode);
        }
Пример #7
0
 private void SaveSettings(SolutionOptions options, string settingsPath)
 {
     string settings = Serializer.ToXmlString(options);
     using (var writer = new StreamWriter(settingsPath))
     {
         writer.Write(settings);
     }
 }
Пример #8
0
 public SolutionBuilder(SolutionOptions options, ILogger logger)
 {
     _options = options;
     _logger = logger;
 }