예제 #1
0
        public static void RemoveProjectReference(this SolutionFile solutionFile, string solutionFilePath, string projectFilePath)
        {
            var projectRelativePath = VsPathUtilities.GetProjectFileRelativeToSolutionDirectoryPath(solutionFilePath, projectFilePath);

            var hasProjectReference = solutionFile.HasProjectReference(projectRelativePath, out var projectReference);

            if (!hasProjectReference)
            {
                return;
            }

            // Is the project reference in a nested solution folder?
            var hasNestedProjectsGlobalSection = solutionFile.GlobalSections.HasNestedProjectsGlobalSection(out var nestedProjectsGlobalSection);

            if (hasNestedProjectsGlobalSection)
            {
                nestedProjectsGlobalSection.ProjectNestings.RemoveAll(x => x.ProjectGUID == projectReference.ProjectGUID);
            }

            // Remove the project configuration platform entries.
            var hasProjectConfigurationPlatformsGlobalSection = solutionFile.GlobalSections.HasProjectConfigurationPlatformsGlobalSection(out var projectConfigurationPlatformsGlobalSection);

            if (hasProjectConfigurationPlatformsGlobalSection)
            {
                projectConfigurationPlatformsGlobalSection.ProjectBuildConfigurationMappings.RemoveAll(x => x.ProjectGUID == projectReference.ProjectGUID);
            }

            // Remove the project reference.
            solutionFile.SolutionFileProjectReferences.Remove(projectReference);
        }
예제 #2
0
        public static bool HasProjectReferenceByProjectFilePath(this SolutionFile solutionFile, string solutionFilePath, string projectFilePath)
        {
            var projectFileRelativePath = VsPathUtilities.GetProjectFileRelativeToSolutionDirectoryPath(solutionFilePath, projectFilePath);

            var hasProjectReference = solutionFile.HasProjectReferenceByProjectFileRelativePath(projectFileRelativePath);

            return(hasProjectReference);
        }
        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);
        }
예제 #4
0
        /// <summary>
        /// Gets all project reference file paths for project in the dependencies solution folder.
        /// Requires the solution file path since the solution file model does not store a file path, and all project references are relative paths, relative to the solution file path.
        /// </summary>
        public static IEnumerable <string> GetProjectReferenceDependencyFilePaths(this SolutionFile solutionFile, string solutionFilePath)
        {
            var projectFilePaths = solutionFile.GetDependencyProjectReferences().Select(projectReference => VsPathUtilities.GetProjectFilePath(solutionFilePath, projectReference.ProjectFileRelativePathValue));

            return(projectFilePaths);
        }