public static SolutionFileProjectReference NewNetCoreOrStandard(string solutionFilePath, string projectFilePath)
        {
            var solutionDirectoryToDependencyProjectRelativeFilePath = VsPathUtilities.GetProjectFileRelativeToSolutionDirectoryPath(solutionFilePath, projectFilePath);

            var projectName = VsPathUtilities.GetProjectName(projectFilePath);

            var solutionFileProjectReference = SolutionFileProjectReference.NewNetCoreOrStandardFromProjectFileRelativePath(projectName, solutionDirectoryToDependencyProjectRelativeFilePath);

            return(solutionFileProjectReference);
        }
        public static SolutionFileProjectReference NewNetCoreOrStandardFromProjectFileRelativePath(string projectName, string projectFileRelativePathValue)
        {
            var solutionFileProjectReference = new SolutionFileProjectReference
            {
                ProjectGUID = Guid.NewGuid(),
                ProjectName = projectName,
                ProjectFileRelativePathValue = projectFileRelativePathValue,
                ProjectTypeGUID = SolutionFileConstants.NetStandardLibraryProjectTypeGUID
            };

            return(solutionFileProjectReference);
        }
示例#3
0
        /// <summary>
        /// Add a solution file project reference to a solution file.
        /// Adds entries for the project reference to the solution configuration platform section and project configuration platform section.
        /// Also ensures that the solution has an extensibility goals section.
        /// </summary>
        public static void AddProjectReference(this SolutionFile solutionFile, SolutionFileProjectReference projectReference)
        {
            solutionFile.SolutionFileProjectReferences.Add(projectReference);

            var solutionConfigurationPlatforms = solutionFile.GlobalSections.AcquireSolutionConfigurationPlatformsGlobalSection();

            var projectConfigurationPlatforms = solutionFile.GlobalSections.AcquireProjectConfigurationPlatformsGlobalSection();

            projectConfigurationPlatforms.AddProjectConfigurations(projectReference.ProjectGUID, solutionConfigurationPlatforms);

            // Somehow, adding a project to a solution in VS adds the Extensibility Globals section. So ensure that the solution file has the Extensibility Globals section.
            solutionFile.EnsureHasExtensibilityGlobals();
        }
示例#4
0
        public static SolutionFileProjectReference AddDependenciesSolutionFolder(this SolutionFile solutionFile)
        {
            var dependenciesSolutionFolder = new SolutionFileProjectReference
            {
                ProjectTypeGUID = Constants.SolutionFolderProjectTypeGUID,
                ProjectName     = Constants.DependenciesSolutionFolderName,
                ProjectFileRelativePathValue = Constants.DependenciesSolutionFolderName,
                ProjectGUID = Guid.NewGuid()
            };

            solutionFile.SolutionFileProjectReferences.Add(dependenciesSolutionFolder);

            return(dependenciesSolutionFolder);
        }
示例#5
0
        /// <summary>
        /// Adds a solution file project reference to the dependencies solution folder of the solution file.
        /// Acquires the dependencies solution folder if not present, and adds the project nesting entry.
        /// </summary>
        public static void AddProjectToDependenciesSolutionFolder(this SolutionFile solutionFile, SolutionFileProjectReference projectReference)
        {
            var dependenciesSolutionFolder = solutionFile.AcquireDependenciesSolutionFolder();

            var projectNesting = new ProjectNesting {
                ProjectGUID = projectReference.ProjectGUID, ParentProjectGUID = dependenciesSolutionFolder.ProjectGUID
            };

            solutionFile.AddProjectNesting(projectNesting);
        }
示例#6
0
        public static void AddProjectReferences(this SolutionFile solutionFile, string solutionFilePath, IEnumerable <string> projectFilePaths)
        {
            var projectReferences = projectFilePaths.Select(projectFilePath => SolutionFileProjectReference.NewNetCoreOrStandard(solutionFilePath, projectFilePath));

            solutionFile.AddProjectReferences(projectReferences);
        }
示例#7
0
        public static bool HasProjectReference(this SolutionFile solutionFile, string projectRelativeFilePath, out SolutionFileProjectReference projectReference)
        {
            projectReference = solutionFile.SolutionFileProjectReferences.Where(x => x.ProjectFileRelativePathValue == projectRelativeFilePath).SingleOrDefault();

            var hasProjectReference = projectReference != default;

            return(hasProjectReference);
        }
示例#8
0
        public static bool HasProjectReference(this SolutionFile solutionFile, SolutionFileProjectReference projectReference)
        {
            var hasProjectReference = solutionFile.HasProjectReferenceByProjectFileRelativePath(projectReference.ProjectFileRelativePathValue);

            return(hasProjectReference);
        }
示例#9
0
        public static bool HasDependenciesSolutionFolder(this SolutionFile solutionFile, out SolutionFileProjectReference dependenciesSolutionFolder)
        {
            dependenciesSolutionFolder = solutionFile.SolutionFileProjectReferences.Where(x => x.ProjectName == Constants.DependenciesSolutionFolderName).SingleOrDefault();

            var hasDependenciesSolutionFolder = dependenciesSolutionFolder != default;

            return(hasDependenciesSolutionFolder);
        }
示例#10
0
        /// <summary>
        /// Adds a project reference to the solution's dependencies folder, checking first to avoid adding duplicates.
        /// </summary>
        public static void AddProjectReferenceDependencyChecked(this SolutionFile solutionFile, string solutionFilePath, string projectFilePath)
        {
            var projectReference = SolutionFileProjectReference.NewNetCoreOrStandard(solutionFilePath, projectFilePath);

            solutionFile.AddProjectReferenceDependencyChecked(projectReference);
        }
示例#11
0
        /// <summary>
        /// Adds a project reference to the solution's dependencies folder, but checks first to avoid adding duplicates.
        /// </summary>
        public static void AddProjectReferenceDependencyChecked(this SolutionFile solutionFile, SolutionFileProjectReference projectReference)
        {
            var hasProjectReference = solutionFile.HasProjectReference(projectReference);

            if (!hasProjectReference)
            {
                solutionFile.AddProjectReferenceAsDependency(projectReference);
            }
        }
示例#12
0
        /// <summary>
        /// Adds a project reference to a solution file under the solution dependencies solution folder.
        /// </summary>
        public static void AddProjectReferenceAsDependency(this SolutionFile solutionFile, SolutionFileProjectReference projectReference)
        {
            solutionFile.AddProjectReference(projectReference);

            solutionFile.AddProjectToDependenciesSolutionFolder(projectReference);
        }