public static void AddProject(this SlnFile slnFile, string fullProjectPath) { if (string.IsNullOrEmpty(fullProjectPath)) { throw new ArgumentException(); } var relativeProjectPath = Path.GetRelativePath( PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), fullProjectPath); if (slnFile.Projects.Any((p) => string.Equals(p.FilePath, relativeProjectPath, StringComparison.OrdinalIgnoreCase))) { Reporter.Output.WriteLine(string.Format( CommonLocalizableStrings.SolutionAlreadyContainsProject, slnFile.FullPath, relativeProjectPath)); } else { ProjectInstance projectInstance = null; try { projectInstance = new ProjectInstance(fullProjectPath); } catch (InvalidProjectFileException e) { Reporter.Error.WriteLine(string.Format( CommonLocalizableStrings.InvalidProjectWithExceptionMessage, fullProjectPath, e.Message)); return; } var slnProject = new SlnProject { Id = projectInstance.GetProjectId(), TypeGuid = projectInstance.GetProjectTypeGuid(), Name = Path.GetFileNameWithoutExtension(relativeProjectPath), FilePath = relativeProjectPath }; slnFile.AddDefaultBuildConfigurations(slnProject); slnFile.AddSolutionFolders(slnProject); slnFile.Projects.Add(slnProject); Reporter.Output.WriteLine( string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, relativeProjectPath)); } }
private void AddProject(SlnFile slnFile, string fullProjectPath) { var relativeProjectPath = PathUtility.GetRelativePath( PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), fullProjectPath); if (slnFile.Projects.Any((p) => string.Equals(p.FilePath, relativeProjectPath, StringComparison.OrdinalIgnoreCase))) { Reporter.Output.WriteLine(string.Format( CommonLocalizableStrings.SolutionAlreadyContainsProject, slnFile.FullPath, relativeProjectPath)); } else { var projectInstance = new ProjectInstance(fullProjectPath); var slnProject = new SlnProject { Id = projectInstance.GetProjectId(), TypeGuid = projectInstance.GetProjectTypeGuid(), Name = Path.GetFileNameWithoutExtension(relativeProjectPath), FilePath = relativeProjectPath }; AddDefaultBuildConfigurations(slnFile, slnProject); AddSolutionFolders(slnFile, slnProject); slnFile.Projects.Add(slnProject); Reporter.Output.WriteLine( string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, relativeProjectPath)); } }
public static void AddProject(this SlnFile slnFile, string fullProjectPath) { if (string.IsNullOrEmpty(fullProjectPath)) { throw new ArgumentException(); } var relativeProjectPath = Path.GetRelativePath( PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), fullProjectPath); if (slnFile.Projects.Any((p) => string.Equals(p.FilePath, relativeProjectPath, StringComparison.OrdinalIgnoreCase))) { Reporter.Output.WriteLine(string.Format( CommonLocalizableStrings.SolutionAlreadyContainsProject, slnFile.FullPath, relativeProjectPath)); } else { ProjectInstance projectInstance = null; try { projectInstance = new ProjectInstance(fullProjectPath); } catch (InvalidProjectFileException e) { Reporter.Error.WriteLine(string.Format( CommonLocalizableStrings.InvalidProjectWithExceptionMessage, fullProjectPath, e.Message)); return; } var slnProject = new SlnProject { Id = projectInstance.GetProjectId(), TypeGuid = projectInstance.GetProjectTypeGuid(), Name = Path.GetFileNameWithoutExtension(relativeProjectPath), FilePath = relativeProjectPath }; // NOTE: The order you create the sections determines the order they are written to the sln // file. In the case of an empty sln file, in order to make sure the solution configurations // section comes first we need to add it first. This doesn't affect correctness but does // stop VS from re-ordering things later on. Since we are keeping the SlnFile class low-level // it shouldn't care about the VS implementation details. That's why we handle this here. slnFile.AddDefaultBuildConfigurations(); slnFile.MapSolutionConfigurationsToProject( projectInstance, slnFile.ProjectConfigurationsSection.GetOrCreatePropertySet(slnProject.Id)); slnFile.AddSolutionFolders(slnProject); slnFile.Projects.Add(slnProject); Reporter.Output.WriteLine( string.Format(CommonLocalizableStrings.ProjectAddedToTheSolution, relativeProjectPath)); } }