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); }
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); }