Exemple #1
0
        private static void LoadSolutionAndProjectList(out string solutionName, out List <Project> projectList)
        {
            solutionName = string.Empty;
            projectList  = new List <Project>();

            string[] Files = Directory.GetFiles(Environment.CurrentDirectory, "*.sln");
            ConsoleDebug.Write($"Found {Files.Length} solution file(s)");

            foreach (string SolutionFileName in Files)
            {
                ConsoleDebug.Write($"  Solution file: {SolutionFileName}");
                Solution NewSolution = new Solution(SolutionFileName);

                solutionName = NewSolution.Name;

                foreach (Project Item in NewSolution.ProjectList)
                {
                    bool   IsIgnored = Item.ProjectType > ProjectType.KnownToBeMSBuildFormat;
                    string Operation = IsIgnored ? "Ignored" : "Parsed";

                    ConsoleDebug.Write($"    Project: {Item.ProjectName} ({Operation})");

                    if (!IsIgnored)
                    {
                        projectList.Add(Item);
                    }
                }
            }

            ConsoleDebug.Write($"Found {projectList.Count} project file(s)");
        }
Exemple #2
0
        private static void WriteNuspec(Nuspec nuspec, bool isDebug, string nuspecIcon)
        {
            if (nuspec.RelativePath.Length > 0)
            {
                ConsoleDebug.Write($"  Processing: {nuspec.RelativePath}");
            }
            else
            {
                ConsoleDebug.Write($"  Processing...");
            }

            InitializeFile(nuspec, isDebug, out string NuspecPath);

            using FileStream Stream   = new FileStream(NuspecPath, FileMode.Append, FileAccess.Write);
            using StreamWriter Writer = new StreamWriter(Stream, Encoding.UTF8);

            Writer.WriteLine("<package xmlns=\"http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd\">");
            Writer.WriteLine("  <metadata>");

            string ApplicationIcon = nuspecIcon.Length > 0 ? nuspecIcon : nuspec.ApplicationIcon;

            WriteMiscellaneousInfo(Writer, nuspec, isDebug, NuspecPath, ApplicationIcon);
            WriteDependencies(Writer, nuspec);
            WriteExtraContentFiles(Writer, isDebug);

            Writer.WriteLine("  </metadata>");
            Writer.Write("</package>");
        }
Exemple #3
0
        private static void FilterProcessedProject(Project project, List <Project> processedProjectList, ref bool hasErrors)
        {
            ConsoleDebug.Write($"  Project file: {project.RelativePath}");

            project.LoadDetails(project.RelativePath);
            bool ProjectHasErrors = project.CheckVersionConsistency(out string WarningOrErrorText);

            hasErrors |= ProjectHasErrors;

            if (WarningOrErrorText.Length > 0)
            {
                if (ProjectHasErrors)
                {
                    ConsoleDebug.Write($"    ERROR: {WarningOrErrorText}", true);
                }
                else
                {
                    ConsoleDebug.Write($"    {WarningOrErrorText}", false);
                }
            }
            else
            {
                FilterProcessedProjectNoWarning(project, processedProjectList);
            }
        }
Exemple #4
0
        private static void FilterProcessedProjects(List <Project> projectList, out List <Project> processedProjectList, out bool hasErrors)
        {
            processedProjectList = new List <Project>();
            hasErrors            = false;

            foreach (Project Item in projectList)
            {
                FilterProcessedProject(Item, processedProjectList, ref hasErrors);
            }

            ConsoleDebug.Write($"Processing {processedProjectList.Count} project file(s)");
        }
Exemple #5
0
        private static void InitializeFile(Nuspec nuspec, bool isDebug, out string nuspecPath)
        {
            string DebugSuffix    = GetDebugSuffix(isDebug);
            string NugetDirectory = isDebug ? "nuget-debug" : "nuget";
            string NuspecFileName = $"{nuspec.Name}{DebugSuffix}.nuspec";

            nuspecPath = Path.Combine(NugetDirectory, NuspecFileName);

            using FileStream FirstStream   = new FileStream(nuspecPath, FileMode.Create, FileAccess.Write);
            using StreamWriter FirstWriter = new StreamWriter(FirstStream, Encoding.ASCII);
            FirstWriter.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

            ConsoleDebug.Write($"     Created: {nuspecPath}");
        }
Exemple #6
0
        private void ExecuteProgram(bool isDebug, bool isMerge, string mergeName, string nuspecDescription, string nuspecIcon, out bool hasErrors)
        {
            ConsoleDebug.Write($"Current Directory: {Environment.CurrentDirectory}");

            CheckOutputDirectory(isDebug, out bool IsDirectoryExisting, out string NugetDirectory);
            if (!IsDirectoryExisting)
            {
                ConsoleDebug.Write($"WARNING: output folder {NugetDirectory} does not exist");
                hasErrors = false;
                return;
            }

            LoadSolutionAndProjectList(out string SolutionName, out List <Project> ProjectList);
            FilterProcessedProjects(ProjectList, out List <Project> ProcessedProjectList, out hasErrors);

            List <Nuspec> NuspecList = new List <Nuspec>();

            if (isMerge)
            {
                MergeProjects(isDebug, SolutionName, ProcessedProjectList, mergeName, nuspecDescription, out Nuspec mergedNuspec, ref hasErrors);

                if (!hasErrors)
                {
                    NuspecList.Add(mergedNuspec);
                    ConsoleDebug.Write("All projects have been merged");
                }
            }
            else
            {
                NuspecList = new List <Nuspec>();
                foreach (Project Project in ProcessedProjectList)
                {
                    NuspecList.Add(Nuspec.FromProject(isDebug, Project));
                }
            }

            foreach (Nuspec Nuspec in NuspecList)
            {
                WriteNuspec(Nuspec, isDebug, nuspecIcon);
            }
        }
Exemple #7
0
        private static void FilterProcessedProjectNoWarning(Project project, List <Project> processedProjectList)
        {
            if (project.Version.Length > 0)
            {
                ConsoleDebug.Write($"    Version: {project.Version}");
            }
            if (project.AssemblyVersion.Length > 0)
            {
                ConsoleDebug.Write($"    Assembly Version: {project.AssemblyVersion}");
            }
            if (project.FileVersion.Length > 0)
            {
                ConsoleDebug.Write($"    File Version: {project.FileVersion}");
            }
            if (project.RepositoryUrl != null)
            {
                ConsoleDebug.Write($"    Repository Url: {project.RepositoryUrl}");
            }
            if (project.FrameworkList.Count > 0)
            {
                string TargetFrameworks = string.Empty;

                foreach (Framework Item in project.FrameworkList)
                {
                    if (TargetFrameworks.Length > 0)
                    {
                        TargetFrameworks += ";";
                    }
                    TargetFrameworks += Item.Name;
                }

                ConsoleDebug.Write($"    Target Framework(s): {TargetFrameworks}");
            }

            if (project.HasVersion && project.IsAssemblyVersionValid && project.IsFileVersionValid && project.HasRepositoryUrl && project.HasTargetFrameworks)
            {
                processedProjectList.Add(project);
            }
        }