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); }
/// <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(); }
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); }
/// <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); }
public static void AddProjectReferences(this SolutionFile solutionFile, string solutionFilePath, IEnumerable <string> projectFilePaths) { var projectReferences = projectFilePaths.Select(projectFilePath => SolutionFileProjectReference.NewNetCoreOrStandard(solutionFilePath, projectFilePath)); solutionFile.AddProjectReferences(projectReferences); }
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); }
public static bool HasProjectReference(this SolutionFile solutionFile, SolutionFileProjectReference projectReference) { var hasProjectReference = solutionFile.HasProjectReferenceByProjectFileRelativePath(projectReference.ProjectFileRelativePathValue); return(hasProjectReference); }
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); }
/// <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); }
/// <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); } }
/// <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); }