예제 #1
0
 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);
 }
예제 #2
0
        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);
            }
        }