コード例 #1
0
        internal static void _InsertNewProjects(string targetSolutionPath, SolutionFile solution, IEnumerable <string> newReferences)
        {
            // Update the project in memory
            string[] solutionLines = _InsertNewProjectsInternal(targetSolutionPath, solution, newReferences);

            // Write it out to the file
            SolutionGenerationUtilities.WriteSolutionFileToDisk(targetSolutionPath, solutionLines);
        }
コード例 #2
0
        /// <summary>
        /// Update the target solution to contain the new projects.
        /// </summary>
        /// <param name="targetSolutionPath">The path to the solution file.</param>
        /// <param name="solution">A <see cref="SolutionFile"/> that represents the solution.</param>
        /// <param name="newReferences">An <see cref="IEnumerable{string}"/> of projects to add to the solution.</param>
        /// <returns>The solution lines modified</returns>
        /// <remarks>
        ///     This internal version allows the lines to be updated in memory
        /// but does not write it to a file. This is done to assist in Unit
        /// Testing these changes.
        /// </remarks>
        internal static string[] _InsertNewProjectsInternal(string targetSolutionPath, SolutionFile solution, IEnumerable <string> newReferences)
        {
            string               solutionRoot             = PathUtilities.AddTrailingSlash(Path.GetDirectoryName(targetSolutionPath));
            List <string>        projectFragmentsToInsert = new List <string>();
            List <string>        dependencyFolderItems    = new List <string>();
            List <string>        projectConfigurationFragmentsToInsert = new List <string>();
            IEnumerable <string> solutionConfigurations = SolutionUtilities.GetSolutionConfigurations(solution);

            // Perform all the generation of the elements to insert
            string dependenciesFolderGuid;
            bool   dependenciesFolderExists = SolutionUtilities.TryGetDepedenciesFolderGuid(solution, out dependenciesFolderGuid);

            if (dependenciesFolderExists != true)
            {
                projectFragmentsToInsert.AddRange(SolutionGenerationUtilities.FragmentForSolutionFolder("Dependencies", dependenciesFolderGuid));
            }

            foreach (string newReference in newReferences)
            {
                (IEnumerable <string> ProjectFragment, string ProjectGuid)solutionFragment = SolutionGenerationUtilities.FragmentForProject(solutionRoot, newReference);
                projectFragmentsToInsert.AddRange(solutionFragment.ProjectFragment);
                dependencyFolderItems.Add(solutionFragment.ProjectGuid);
                projectConfigurationFragmentsToInsert.AddRange(SolutionGenerationUtilities.FragmentForSolutionConfiguration(solutionFragment.ProjectGuid, solutionConfigurations));
            }

            // We only want to read the file once
            string[] solutionLines = File.ReadLines(targetSolutionPath).ToArray();

            // Now each of these build upon each other; we need to evaluate
            // each of the actions completely prior to the next step.
            solutionLines = _InsertProjectFragments(solutionLines, projectFragmentsToInsert).ToArray();
            solutionLines = _InsertDependencyFolderItems(solutionLines, dependenciesFolderGuid, dependencyFolderItems).ToArray();
            solutionLines = _InsertProjectConfigurationFragments(solutionLines, projectConfigurationFragmentsToInsert).ToArray();

            return(solutionLines);
        }