public int AddProjectToProjectReferences(string framework, IEnumerable <string> refs) { int numberOfAddedReferences = 0; ProjectItemGroupElement itemGroup = ProjectRootElement.FindUniformOrCreateItemGroupWithCondition( ProjectItemElementType, framework); foreach (var @ref in refs.Select((r) => PathUtility.GetPathWithBackSlashes(r))) { if (ProjectRootElement.HasExistingItemWithCondition(framework, @ref)) { Reporter.Output.WriteLine(string.Format( CommonLocalizableStrings.ProjectAlreadyHasAreference, @ref)); continue; } numberOfAddedReferences++; itemGroup.AppendChild(ProjectRootElement.CreateItemElement(ProjectItemElementType, @ref)); Reporter.Output.WriteLine(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @ref)); } return(numberOfAddedReferences); }
internal static int AddProjectToProjectReference(ProjectRootElement root, string framework, IEnumerable <string> refs) { int numberOfAddedReferences = 0; const string ProjectItemElementType = "ProjectReference"; ProjectItemGroupElement itemGroup = root.FindUniformOrCreateItemGroupWithCondition(ProjectItemElementType, framework); foreach (var @ref in refs.Select((r) => NormalizeSlashesForMsbuild(r))) { if (root.HasExistingItemWithCondition(framework, @ref)) { Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectAlreadyHasAreference, @ref)); continue; } numberOfAddedReferences++; itemGroup.AppendChild(root.CreateItemElement(ProjectItemElementType, @ref)); Reporter.Output.WriteLine(string.Format(LocalizableStrings.ReferenceAddedToTheProject, @ref)); } return(numberOfAddedReferences); }