void AppendDebugElement(XmlDocument nugetDebugXml, CsProject referencingProject, NuGetClientHelper.NuGetPackage debugPackage, SlnxHandler debugHandler) { var propertyGroup = nugetDebugXml.CreateNode(XmlNodeType.Element, "PropertyGroup", null); nugetDebugXml.DocumentElement.AppendChild(propertyGroup); propertyGroup.InnerXml = string.Format("<{0}>1</{0}>", NuGetClientHelper.NuGetPackage.GetDebugEnvironmentVariableKey(debugPackage.Identity.Id)); var itemGroup = nugetDebugXml.CreateNode(XmlNodeType.Element, "ItemGroup", null); nugetDebugXml.DocumentElement.AppendChild(itemGroup); itemGroup.InnerXml = ""; HashSet <string> projectReferences = new HashSet <string>(); var projectCandidates = debugHandler.Projects.Where(x => !x.IsTestProject); foreach (var referencedProject in projectCandidates) { if (referencingProject.AssemblyReferences.Any(r => referencedProject.Name == Path.GetFileNameWithoutExtension(r.HintPath))) { projectReferences.Add(referencedProject.FullPath); } } var matchingPackage = referencingProject.PackageReferencesFromSlnX.Where(x => x.Identity.Id.Equals(debugPackage.Identity.Id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (matchingPackage != null) //The debug project is referenced as NuGet package, add all Projects in the solution { projectCandidates.ToList().ForEach(x => projectReferences.Add(x.FullPath)); } foreach (var p in projectReferences) { itemGroup.InnerXml = string.Format("{0}<ProjectReference Include=\"{1}\"/>", itemGroup.InnerXml, p); } }
XmlDocument TryGetDebugXmlDoc(CsProject proj, NuGetClientHelper.NuGetPackage package) { if (proj.AssemblyReferences != null) { foreach (var r in proj.AssemblyReferences) { if (package.Libraries.Any(x => Path.GetFileName(x) == Path.GetFileName(r.HintPath))) { var newDocument = new XmlDocument(); var root = newDocument.CreateNode(XmlNodeType.Element, "Project", null); newDocument.AppendChild(root); return(newDocument); } } if (proj.AllPackageReferences.Any(x => x.Identity.Id.Equals(package.Identity.Id, StringComparison.OrdinalIgnoreCase))) { var newDocument = new XmlDocument(); var root = newDocument.CreateNode(XmlNodeType.Element, "Project", null); newDocument.AppendChild(root); return(newDocument); } } return(null); }
private List <CsProject> InspectProjects(ProjectType[] requestedProjectsXmlType, IEnumerable <string> knownProjects, string skip, string enforcedContainer) { var csProjects = new List <CsProject>(); List <string> skipList = new List <string>(); if (!string.IsNullOrEmpty(skip)) { foreach (var s in skip.Split(';')) { skipList.Add(SafeExpandEnvironmentVariables(s)); } } List <ProjectType> requestedProjects = new List <ProjectType>(); //Expand all wildcards foreach (var reqProjXmlType in requestedProjectsXmlType) { if (reqProjXmlType.name.Contains("*")) //Check wildcards { var wildCardMatches = knownProjects.Where((x) => FilterProjectByName(x, reqProjXmlType.name, skipList)).ToList(); var wildCardProjects = wildCardMatches.ConvertAll <ProjectType>((name) => { var p = new ProjectType(); p.name = Path.GetFileNameWithoutExtension(name); p.container = reqProjXmlType.container; return(p); } ); requestedProjects.AddRange(wildCardProjects); } else { requestedProjects.Add(reqProjXmlType); } } //Check projects's existance and ambiguity (also for wildcard imported projects) foreach (var requestedProject in requestedProjects) { var requestedCsProjName = string.Format("{0}.{1}", requestedProject.name, CsProject.FileExtension); var knownProject = knownProjects.Where((x) => FilterProjectByName(x, requestedCsProjName, skipList)).ToList(); if (knownProject.Count == 0) { throw new Exception(string.Format("Project '{0}' not found!", requestedProject.name)); } if (knownProject.Count > 1) { throw new Exception(string.Format("Project '{0}' is ambiguous!\n\n{1}", requestedProject.name, string.Join("\n\n", knownProject))); } var container = requestedProject.container; if (!string.IsNullOrEmpty(enforcedContainer)) { container = string.Join("/", enforcedContainer, container); } var p = new CsProject(knownProject[0], container, _fileWriter, _logger); csProjects.Add(p); } return(csProjects); }