/// <summary>
        /// Create a DotnetSolution from the sln.
        /// </summary>
        /// <param name="globalInfo">The StandardGlobalInfo</param>
        /// <param name="projectToPublishPredicate">
        /// The predicate used to filter the project to publish. By default the predicate is p => !p.Path.Segments.Contains
        /// </param>
        /// <returns></returns>
        public static DotnetSolution FromSolutionInCurrentWorkingDirectory(
            StandardGlobalInfo globalInfo)
        {
            string solutionFileName = System.IO.Path.GetFileName(
                globalInfo.Cake.GetFiles("*.sln",
                                         new GlobberSettings
            {
                Predicate = p => !System.IO.Path.GetFileName(p.Path.FullPath).EndsWith(".local.sln", StringComparison.OrdinalIgnoreCase)
            }).Single().FullPath
                );
            SolutionParserResult sln = globalInfo.Cake.ParseSolution(solutionFileName);

            List <SolutionProject> projects = sln
                                              .Projects
                                              .Where(p => !(p is SolutionFolder) &&
                                                     p.Name != "CodeCakeBuilder")
                                              .ToList();
            List <SolutionProject> projectsToPublish = projects.Where(
                p => ((bool?)XDocument.Load(p.Path.FullPath)
                      .Root
                      .Elements("PropertyGroup")
                      .Elements("IsPackable").LastOrDefault() ?? true) == true
                )
                                                       .ToList();

            return(new DotnetSolution(globalInfo, solutionFileName, projects, projectsToPublish));
        }
示例#2
0
        // ---------------- Functions ----------------

        public override void Run(BuildContext context)
        {
            CakeLicenseHeaderUpdaterSettings settings = new CakeLicenseHeaderUpdaterSettings
            {
                LicenseString = currentLicense,
                Threads       = 0,
            };

            settings.OldHeaderRegexPatterns.Add(oldLicenseRegex1);
            settings.OldHeaderRegexPatterns.Add(oldLicenseRegex2);
            settings.OldHeaderRegexPatterns.Add(oldLicenseRegex3);

            settings.FileFilter = delegate(FilePath path)
            {
                if (Regex.IsMatch(path.ToString(), @"[/\\]obj[/\\]"))
                {
                    return(false);
                }
                if (Regex.IsMatch(path.ToString(), @"[/\\]bin[/\\]"))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            };

            List <FilePath> files = new List <FilePath>();

            SolutionParserResult slnResult = context.ParseSolution(context.Solution);

            foreach (SolutionProject proj in slnResult.Projects)
            {
                if (proj.Path.ToString().EndsWith(".csproj") || proj.Path.ToString().EndsWith(".shproj"))
                {
                    string glob = proj.Path.GetDirectory() + "/**/*.cs";
                    files.AddRange(context.GetFiles(glob));
                }
            }

            context.UpdateLicenseHeaders(files, settings);
        }
示例#3
0
        /// <summary>
        /// Create a DotnetSolution from the sln.
        /// </summary>
        /// <param name="globalInfo">The StandardGlobalInfo</param>
        /// <param name="projectToPublishPredicate">
        /// The predicate used to filter the project to publish. By default the predicate is p => !p.Path.Segments.Contains
        /// </param>
        /// <returns></returns>
        public static DotnetSolution FromSolutionInCurrentWorkingDirectory(
            StandardGlobalInfo globalInfo)
        {
            string solutionFileName  = "MarketFlight.sln";
            SolutionParserResult sln = globalInfo.Cake.ParseSolution(solutionFileName);

            List <SolutionProject> projects = sln
                                              .Projects
                                              .Where(p => !(p is SolutionFolder) &&
                                                     p.Name != "CodeCakeBuilder")
                                              .ToList();
            List <SolutionProject> projectsToPublish = projects.Where(
                p => ((bool?)XDocument.Load(p.Path.FullPath)
                      .Root
                      .Elements("PropertyGroup")
                      .Elements("IsPackable").LastOrDefault() ?? true) == true
                )
                                                       .ToList();

            return(new DotnetSolution(globalInfo, solutionFileName, projects, projectsToPublish));
        }
示例#4
0
        // ---------------- Functions ----------------

        /// <summary>
        /// Performs an action on all of the project files contained within a solution.
        /// </summary>
        /// <param name="filter">
        /// Use this to filter out which <see cref="SolutionProject"/> you do not
        /// want to perform the action on.  Have this return false to not
        /// perform the action on the passed in <see cref="SolutionProject"/>
        /// </param>
        public static void PerformActionOnSolutionProjectFiles(
            this ICakeContext context,
            FilePath solutionPath,
            Action <SolutionProject> action,
            Func <SolutionProject, bool> filter = null
            )
        {
            ArgumentChecker.IsNotNull(action, nameof(action));

            SolutionParserResult slnResult = context.ParseSolution(solutionPath);

            slnResult.Projects.SerialPerformActionOnList(
                delegate(SolutionProject project)
            {
                if (filter != null && filter(project))
                {
                    action(project);
                }
            },
                $"Errors when parsing a {nameof( SolutionProject )}"
                );
        }
 /// <summary>
 /// Gets the SolutionProjects, excluding any SolutionFolders
 /// </summary>
 /// <param name="projects">The SolutionProject collection</param>
 /// <returns>The SolutionProjects</returns>
 /// <example>
 /// Gets an absolute assembly path for a project
 /// <code>
 /// SolutionProjectResult result = ParseSolution(new FilePath("test.sln"));
 /// result.GetProjects();
 /// </code>
 /// </example>
 public static IEnumerable <SolutionProject> GetProjects(this SolutionParserResult projects)
 {
     return(projects.Projects.Where(x => !IsSolutionFolder(x)));
 }