コード例 #1
0
 private static bool IsProjNetStandard(string projectPath)
 {
     NuspecCreatorHelper.LoadProject(projectPath, out _, out _, out var csproj);
     return
         (csproj.Elements("PropertyGroup").Any(e => e.Elements("TargetFramework").Any()) ||
          csproj.Elements("PropertyGroup").Any(e => e.Elements("TargetFrameworks").Any()));
 }
コード例 #2
0
        protected string GetFrameworkVersion(string projectPath)
        {
            NuspecCreatorHelper.LoadProject(projectPath, out XDocument _, out XNamespace xmlns, out XElement proj);

            var targetFrameworkVersion = proj
                                         .Elements(xmlns + "PropertyGroup")
                                         .Elements(xmlns + TargetFrameworkElement)
                                         .Select(el => el.Value)
                                         .FirstOrDefault();

            if (string.IsNullOrEmpty(targetFrameworkVersion))
            {
                var targetFrameworksVersion = proj
                                              .Elements(xmlns + "PropertyGroup")
                                              .Elements(xmlns + "TargetFrameworks")
                                              .Select(el => el.Value)
                                              .FirstOrDefault();

                targetFrameworkVersion = targetFrameworksVersion.Split(';').FirstOrDefault();
            }

            if (string.IsNullOrEmpty(targetFrameworkVersion))
            {
                return(null);
            }

            return(FormatFrameworkVersion(targetFrameworkVersion));
        }
コード例 #3
0
        /// <summary>
        /// Gets the NuGet packages a given project is depended on
        /// </summary>
        /// <param name="projectFolder"></param>
        /// <param name="projectPath"></param>
        /// <returns></returns>
        public IList <DependencyInfo> GetDependenciesFromProject(string projectFolder, string projectPath)
        {
            DebugOut(() => $"\r\n\r\nGetDependenciesFromProject({projectFolder}, {projectPath})\r\n");

            XNamespace xmlns;
            XElement   proj;

            NuspecCreatorHelper.LoadProject(projectPath, out XDocument csProj, out xmlns, out proj);

            var noneElements = proj.Elements(xmlns + "ItemGroup").Elements(xmlns + "None");

            var packagesFileName = noneElements.Where(el =>
                                                      el.Attribute("Include") != null && el.Attribute("Include").Value.ToLower() == "packages.config")
                                   .Select(el => el.Attribute("Include").Value)
                                   .FirstOrDefault();

            if (packagesFileName == null)
            {
                return(new DependencyInfo[0]);
            }

            string packagesFile;

            packagesFile = projectFolder + @"\" + packagesFileName;

            DebugOut(() => $"packagesFile: {packagesFile}");

            var dependencies = GetDependencies(packagesFile);

            return(dependencies);
        }
コード例 #4
0
        /// <summary>
        /// Gets the framework references for a given project file
        /// </summary>
        /// <param name="projectFolder"></param>
        /// <param name="projectPath"></param>
        /// <returns></returns>
        public List <DependencyInfo> GetFrameworkReferences(string projectFolder, string projectPath)
        {
            DebugOut(() => $"\r\n\r\nGetFrameworkReferences({projectFolder}, {projectPath})\r\n");

            XNamespace xmlns;
            XElement   proj;

            NuspecCreatorHelper.LoadProject(projectPath, out XDocument csProj, out xmlns, out proj);

            var referencedBinaryFiles = proj.Elements(xmlns + "ItemGroup")
                                        .SelectMany(el => el.Elements(xmlns + "Reference"))
                                        .Where(el => el.Attribute("Include") != null && !el.Elements(xmlns + "HintPath").Any())
                                        .Select(el => el.Attribute("Include").Value)
                                        .ToList();

            // E.g. <frameworkAssembly assemblyName="System.Speech" targetFramework=".NETFramework4.5" />

            var items = referencedBinaryFiles
                        .Select(el =>
                                new DependencyInfo(
                                    ElementType.FrameworkReference,
                                    new XElement("frameworkAssembly",
                                                 new XAttribute("assemblyName", el))))
                        .ToList();

            return(items);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: pub-comp/building
        public static void Main(string[] args)
        {
            CommandLineArguments cla;

            if (!TryParseArguments(args, out cla))
            {
                WriteError();
                return;
            }

            if (cla.Mode != Mode.Solution)
            {
                NusPecCreatorFactory.GetCreator(cla.ProjPath).CreatePackage(
                    cla.ProjPath, cla.DllPath, cla.IsDebug, cla.DoCreateNuPkg, cla.DoIncludeCurrentProj, cla.PreReleaseSuffixOverride);
            }
            else
            {
                NuspecCreatorBase.SlnOutputFolder = cla.BinFolder;

                NuspecCreatorHelper.CreatePackages(
                    cla.BinFolder, cla.SolutionFolder, cla.IsDebug, cla.DoCreateNuPkg, cla.DoIncludeCurrentProj, cla.PreReleaseSuffixOverride);
            }

            //Console.ReadKey();
        }
コード例 #6
0
        private static string GetTargetFrameworks(string projectPath)
        {
            NuspecCreatorHelper.LoadProject(projectPath, out _, out var xmlns, out var proj);
            var propGroups       = proj.Elements(xmlns + "PropertyGroup").ToList();
            var targetFrameworks = propGroups.FirstOrDefault(pg => pg.Elements("TargetFrameworks").Any())
                                   ?.Element("TargetFrameworks")?.Value;

            return(targetFrameworks);
        }
コード例 #7
0
        /// <summary>
        /// Checks if a project contains a file with a given name
        /// </summary>
        /// <param name="projectPath"></param>
        /// <param name="file"></param>
        /// <param name="isProjNetStandard"></param>
        /// <returns></returns>
        private bool DoesProjectContainFile(string projectPath, string file)
        {
            DebugOut(() => $"\r\n\r\nDoesProjectContainFile({projectPath}, {file})\r\n");

            NuspecCreatorHelper.LoadProject(projectPath, out var _, out var xmlns, out var proj);

            var codeElements = proj.Elements(xmlns + "ItemGroup").Elements(xmlns + "Compile");
            var noneElements = proj.Elements(xmlns + "ItemGroup").Elements(xmlns + "None");

            return(DoesProjectContainFile(projectPath, file, noneElements, codeElements));
        }
コード例 #8
0
        protected static string GetAssemblyName(string projectPath)
        {
            NuspecCreatorHelper.LoadProject(projectPath, out _, out var xmlns, out var proj);

            var propGroups          = proj.Elements(xmlns + "PropertyGroup");
            var assemblyNameElement = propGroups.Elements(xmlns + "AssemblyName").FirstOrDefault();

            var asmName = assemblyNameElement?.Value ?? Path.GetFileName(projectPath)?.Replace(".csproj", String.Empty).TrimEnd('.');

            return(asmName);
        }
コード例 #9
0
        protected override IEnumerable <DependencyInfo> GetContentFilesForNetStandard(string projectPath,
                                                                                      List <DependencyInfo> files)
        {
            const string content   = "content\\";
            const string targetDir = @"contentFiles\any\any\";

            if (files.Count == 0)
            {
                return(new List <DependencyInfo>());
            }

            NuspecCreatorHelper.LoadProject(projectPath, out _, out var xmlns, out _);
            var result = files.Where(f =>
                                     !f.Element.Attribute(xmlns + "target")?.Value?.TrimStart(content.ToCharArray())?.Contains("\\") ??
                                     false)
                         .Select(f => new DependencyInfo(f.ElementType, new XElement(f.Element))).ToList();

            foreach (var d in result)
            {
                var v = d.Element.Attribute(xmlns + "target")?.Value;
                d.Element.Attribute(xmlns + "target")?.SetValue(targetDir + v.TrimStart(content.ToCharArray()));
            }

            var includedFolders = files.Where(f =>
                                              f.Element.Attribute(xmlns + "target")?.Value?.Contains(content) ?? false)
                                  .Select(f => f.Element.Attribute(xmlns + "target")?.Value?.TrimStart(content.ToCharArray()))
                                  .Where(f => f.Contains("\\")).Select(f => f.Remove(f.IndexOf("\\"))).Distinct().ToList();

            var srcDir = files.Where(f => f.Element.Attribute(xmlns + "target")?.Value?.Contains(content) ?? false)
                         .Select(f => f.Element.Attribute(xmlns + "src")?.Value)
                         .FirstOrDefault();

            if (string.IsNullOrEmpty(srcDir))
            {
                return(result);
            }
            srcDir = srcDir.Substring(0, srcDir.IndexOf(content) + content.Length);

            result.AddRange(includedFolders.Select(s =>
                                                   new DependencyInfo(
                                                       ElementType.ContentFile,
                                                       new XElement("file",
                                                                    new XAttribute("src", srcDir + s + @"\**"),
                                                                    new XAttribute("target", targetDir + s))))
                            .ToList());

            return(result);
        }
コード例 #10
0
        public List <DependencyInfo> GetContentFiles(
            string nuspecFolder, string projectFolder, string projectPath,
            string srcFolder = @"content\", string destFolder = @"content\",
            bool flattern    = false, ElementType elementType = ElementType.ContentFile)
        {
            DebugOut(() => $"\r\n\r\nGetContentFiles({nuspecFolder}, {projectFolder}, {projectPath})\r\n");

            XNamespace xmlns;
            XElement   proj;

            NuspecCreatorHelper.LoadProject(projectPath, out XDocument csProj, out xmlns, out proj);

            srcFolder = srcFolder.ToLower();

            var contentElements = GetContentElements(projectPath, srcFolder, elementType);

            var relativeProjectFolder = AbsolutePathToRelativePath(projectFolder, nuspecFolder + "\\");

            List <DependencyInfo> items;

            if (!flattern)
            {
                items = contentElements
                        .Select(s =>
                                new DependencyInfo(
                                    elementType,
                                    new XElement("file",
                                                 new XAttribute("src", Path.Combine(relativeProjectFolder, s.src)),
                                                 new XAttribute("target", s.target))))
                        .ToList();
            }
            else
            {
                // ReSharper disable AssignNullToNotNullAttribute
                items = contentElements
                        .Select(s =>
                                new DependencyInfo(
                                    elementType,
                                    new XElement("file",
                                                 new XAttribute("src", Path.Combine(relativeProjectFolder, s.src)),
                                                 new XAttribute("target", Path.Combine(destFolder, Path.GetFileName(s.target))))))
                        .ToList();
                // ReSharper enable AssignNullToNotNullAttribute
            }

            return(items);
        }
コード例 #11
0
        private List <string> GetProjectIncludeFiles(string projectPath, out List <string> verList, out XNamespace xmlns,
                                                     out XElement proj, bool isFileNuget)
        {
            verList = new List <string>();
            NuspecCreatorHelper.LoadProject(projectPath, out _, out xmlns, out proj);
            var x       = xmlns;
            var projref = proj?.Elements(xmlns + "ItemGroup")?.Elements(xmlns + "ProjectReference")?.Where(pr =>
            {
                var file = pr.Attribute(x + "Include")?.Value ?? pr.LastAttribute.Value;
                file     = Path.Combine(Path.GetDirectoryName(projectPath) ?? string.Empty, file);
                file     = Path.Combine(Path.GetDirectoryName(file) ?? "", "NuGetPack.config");
                return(isFileNuget ? File.Exists(file) : !File.Exists(file));
            })
                          .Select(f => f.Attribute(x + "Include")?.Value ?? f.LastAttribute.Value).ToList();

            if (projref.Count == 0)
            {
                return(projref);
            }

            for (var i = 0; i < projref.Count; i++)
            {
                var pr      = projref[i];
                var incProj = Path.Combine(Path.GetDirectoryName(projectPath) ?? string.Empty, pr);
                NuspecCreatorHelper.LoadProject(incProj, out _, out x, out var prj);
                var ver = prj?.Element(xmlns + "PropertyGroup")?.Element(xmlns + "Version")?.Value;
                ver = ver ?? prj?.Element(xmlns + "PropertyGroup")?.Element(xmlns + "FileVersion")?.Value;
                ver = ver ?? prj?.Element(xmlns + "PropertyGroup")?.Element(xmlns + "AssemblyVersion")?.Value;
                if (string.IsNullOrEmpty(ver))
                {
                    var dllFile = GetDllNameFromProjectName(incProj);
                    if (!string.IsNullOrEmpty(dllFile))
                    {
                        ver = ver ?? FileVersionInfo.GetVersionInfo(dllFile).FileVersion;
                        ver = ver ?? FileVersionInfo.GetVersionInfo(dllFile).ProductVersion;
                    }
                }
                ver = ver ?? "1.0.0";
                verList.Add(ver);

                var asem = GetAssemblyName(incProj);
                projref[i] = asem;
            }

            return(projref);
        }
コード例 #12
0
        /// <summary>
        /// Gets the path and name of the binary created by a project
        /// </summary>
        /// <param name="projectPath"></param>
        /// <param name="assemblyName"></param>
        /// <param name="isDebug"></param>
        /// <param name="buildMachineBinFolder"></param>
        /// <param name="assemblyPath"></param>
        public void GetAssemblyNameAndPath(
            string projectPath, out string assemblyName, bool isDebug, string buildMachineBinFolder,
            out string assemblyPath)
        {
            DebugOut(() => $"\r\n\r\nGetAssemblyName({projectPath})\r\n");

            NuspecCreatorHelper.LoadProject(projectPath, out var csProj, out _, out _);

            var asmName = GetAssemblyName(projectPath);

            if (asmName.StartsWith("$"))
            {
                // Inside a VSIX template output project
                assemblyName = null;
                assemblyPath = null;
                return;
            }

            var projectFolder = Path.GetDirectoryName(projectPath);

            var outputPath = GetOutputPath(csProj, isDebug, projectFolder);

            if (!Directory.Exists(outputPath) ||
                !Directory.GetFiles(outputPath).Any(f =>
                                                    f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe"))
                )
            {
                outputPath = buildMachineBinFolder;
            }

            DebugOut(() => "outputPath = " + outputPath);

            var dllExe = new[] { ".dll", ".exe" };

            var asmFile = Directory.GetFiles(outputPath).FirstOrDefault(f =>
                                                                        Path.GetFileNameWithoutExtension(f) == asmName &&
                                                                        dllExe.Contains(Path.GetExtension(f).ToLower()));

            if (asmFile == null)
            {
                throw new ApplicationException($"Could not find path for {asmName}, searched {outputPath}");
            }

            assemblyName = asmName;
            assemblyPath = asmFile;
        }
コード例 #13
0
        private IEnumerable <dynamic> GetContentElements(string projectPath, string srcFolder = @"content\", ElementType elementType = ElementType.ContentFile)
        {
            XNamespace xmlns;
            XElement   proj;

            NuspecCreatorHelper.LoadProject(projectPath, out XDocument _, out xmlns, out proj);

            srcFolder = srcFolder.ToLower();

            var contentElements = proj.Elements(xmlns + "ItemGroup").Elements()
                                  .Where(el => el.Attribute("Include") != null)
                                  .Select(el =>
                                          new
            {
                src    = el.Attribute("Include").Value,
                target = GetContentFileTarget(el, xmlns) ??
                         el.Attribute("Include").Value
            })
                                  .Where(st => st.target.ToLower().StartsWith(srcFolder) && st.target.ToLower() != srcFolder)
                                  .Union(elementType == ElementType.ContentFile ? GetConcreateContentElements(projectPath) : new List <dynamic>());

            return(contentElements);
        }
コード例 #14
0
        /// <summary>
        /// Get referenced projects' output binaries that this NuSpec should include
        /// </summary>
        /// <param name="nuspecFolder"></param>
        /// <param name="projectFolder"></param>
        /// <param name="projectPath"></param>
        /// <param name="isDebug"></param>
        /// <param name="buildMachineBinFolder"></param>
        /// <returns></returns>
        public List <DependencyInfo> GetBinaryReferences(
            string nuspecFolder, string projectFolder, string projectPath, bool isDebug, string buildMachineBinFolder)
        {
            DebugOut(() =>
                     $"\r\n\r\nGetBinaryReferences({projectFolder}, {projectPath}, {isDebug}, {buildMachineBinFolder})\r\n");

            NuspecCreatorHelper.LoadProject(projectPath, out var csProj, out _, out _);

            var outputPath = GetOutputPath(csProj, isDebug, projectFolder);

            if (!Directory.Exists(outputPath) ||
                !Directory.GetFiles(outputPath).Any(f =>
                                                    f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe"))
                )
            {
                outputPath = buildMachineBinFolder;
            }

            DebugOut(() => "outputPath = " + outputPath);

            var relativeOutputPath = AbsolutePathToRelativePath(outputPath, nuspecFolder + "\\");

            var versionFolder = "net" + (GetFrameworkVersion(projectPath) ?? "45");

            var files = GetProjectBinaryFiles(projectPath, outputPath);

            var items = files
                        .Select(file =>
                                new DependencyInfo(
                                    ElementType.LibraryFile,
                                    new XElement("file",
                                                 new XAttribute("src", Path.Combine(relativeOutputPath, Path.GetFileName(file))),
                                                 new XAttribute("target", Path.Combine(@"lib\" + versionFolder + @"\", Path.GetFileName(file)))
                                                 ))).ToList();

            return(items);
        }
コード例 #15
0
        /// <summary>
        /// Get the source files of the given project file
        /// </summary>
        /// <param name="nuspecFolder"></param>
        /// <param name="projectFolder"></param>
        /// <param name="projectPath"></param>
        /// <returns></returns>
        public List <DependencyInfo> GetSourceFiles(string nuspecFolder, string projectFolder, string projectPath)
        {
            DebugOut(() => $"\r\n\r\nGetSourceFiles({projectFolder}, {projectPath})\r\n");

            var projectName = Path.GetFileNameWithoutExtension(projectPath);

            XNamespace xmlns;
            XElement   proj;

            NuspecCreatorHelper.LoadProject(projectPath, out XDocument csProj, out xmlns, out proj);

            if (proj == null)
            {
                throw new ApplicationException($"Could find namespace in load project file {projectPath}");
            }

            var codeElements = proj.Elements(xmlns + "ItemGroup").Elements(xmlns + "Compile");

            // TODO: Remove commented out line after confirming it is redundant
            //var noneElements = proj.Elements(xmlns + "ItemGroup").Elements(xmlns + "None");

            var relativeProjectFolder = AbsolutePathToRelativePath(projectFolder, nuspecFolder + "\\");

            var items = codeElements//.Union(noneElements)
                        .Where(el => el.Attribute("Include") != null &&
                               !el.Attribute("Include").Value.StartsWith(".."))
                        .Select(el => el.Attribute("Include").Value)
                        .Select(s =>
                                new DependencyInfo(
                                    ElementType.SourceFile,
                                    new XElement("file",
                                                 new XAttribute("src", Path.Combine(relativeProjectFolder, s)),
                                                 new XAttribute("target", Path.Combine(@"src\", projectName, s)))))
                        .ToList();

            return(items);
        }
コード例 #16
0
        /// <summary>
        /// Gets the project references for a given project file
        /// </summary>
        /// <param name="projectPath"></param>
        /// <param name="referencesContainNuGetPackConfig">
        /// Enables filtering only references that should be NuGet dependencies (true),
        /// only references that should not be NuGet dependencies (false),
        /// or no filtering (null)
        /// </param>
        /// <returns></returns>
        public List <string> GetReferences(string projectPath, bool?referencesContainNuGetPackConfig = null)
        {
            XNamespace xmlns;
            XElement   proj;

            NuspecCreatorHelper.LoadProject(projectPath, out XDocument csProj, out xmlns, out proj);

            var elements = GetProjectReference(proj, xmlns);

            var references = elements
                             .Select(r => r.Attribute("Include").Value)
                             .ToList();

            if (!referencesContainNuGetPackConfig.HasValue)
            {
                return(references);
            }

            var projectFolder = Path.GetDirectoryName(projectPath);

            var results = new List <string>();

            foreach (var reference in references)
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                var referencePath = Path.GetFullPath(Path.Combine(projectFolder, reference));

                var isPkgProject = DoesProjectContainFile(referencePath, "nugetpack.config");

                if (isPkgProject == referencesContainNuGetPackConfig.Value)
                {
                    results.Add(reference);
                }
            }

            return(results);
        }
コード例 #17
0
        public override List <DependencyInfo> GetBinaryFiles(
            string nuspecFolder, string projectFolder, string projectPath, bool isDebug)
        {
            NuspecCreatorHelper.LoadProject(projectPath, out var csProj, out _, out _);

            var outputPath = GetOutputPath(csProj, isDebug, projectFolder);

            if (!Directory.Exists(outputPath) ||
                !Directory.GetFiles(outputPath).Any(f =>
                                                    f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe"))
                )
            {
                outputPath = nuspecFolder;
            }

            outputPath = SlnOutputFolder ?? outputPath;


            var frameworks = GetProject(projectPath, outputPath, out var pathHeader);

            var files        = new List <string>();
            var includeFiles = GetProjectIncludeFiles(projectPath, out _, out _, out _, false);
            var outPath      = outputPath.TrimEnd('\\').ToLower();

            outPath = outPath.EndsWith(frameworks[0].ToLower())
                ? outPath.Substring(0, outPath.Length - frameworks[0].Length)
                : outputPath;
            foreach (var framework in frameworks)
            {
                files.AddRange(includeFiles
                               .Where(f => File.Exists(Path.Combine(outPath, Path.Combine(framework, f + ".DLL"))))
                               .Select(f => outputPath != outPath
                        ? $"..\\{framework}\\{f}.DLL"
                        : $"{framework}\\{f}.DLL").ToList());
                files.AddRange(includeFiles
                               .Where(f => File.Exists(Path.Combine(outPath, Path.Combine(framework, f + ".PDB"))))
                               .Select(f => outputPath != outPath
                        ? $"..\\{framework}\\{f}.PDB"
                        : $"{framework}\\{f}.PDB").ToList());
            }

            var items = CreateBinFilesDepInfoList(frameworks, files);

            files.Clear();

            outPath = SlnOutputFolder != null?Path.Combine(outputPath, frameworks.First()) : outputPath;

            if (frameworks.Length < 2 &&
                Directory.GetFiles(Path.Combine(outPath, pathHeader)).Any(f =>
                                                                          f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe")))
            {
                files = GetProjectBinaryFiles(projectPath, outPath)
                        .Select(Path.GetFileName).ToList();
                files = files.Select(f =>
                                     SlnOutputFolder == null ? $"..\\{frameworks[0]}\\{f}" : $"{frameworks[0]}\\{f}").ToList();
                items.AddRange(CreateBinFilesDepInfoList(frameworks, files));
            }
            else
            {
                foreach (var framework in frameworks)
                {
                    files.AddRange(GetProjectBinaryFiles(projectPath,
                                                         Path.Combine(outputPath, SlnOutputFolder == null ? $"..\\{framework}" : framework))
                                   .Select(f =>
                    {
                        var frmwrk = f.Substring(Path.GetDirectoryName(Path.GetDirectoryName(f)).Length)
                                     .TrimStart('\\');
                        var prevDir = !string.IsNullOrEmpty(SlnOutputFolder) ? string.Empty : @"..\";
                        return(prevDir + frmwrk);
                    }).ToList());
                }

                items.AddRange(files
                               .Select(s =>
                                       new DependencyInfo(
                                           ElementType.LibraryFile,
                                           new XElement("file",
                                                        new XAttribute("src", s),
                                                        new XAttribute("target", $"lib\\{ExtractFramework(s)}"))))
                               .ToList());
            }

            return(items);
        }
コード例 #18
0
        private XElement GetPackageDependenciesNetStandard(string projectPath, List <XElement> projDependencies)
        {
            var targetFrameworks = GetTargetFrameworks(projectPath);

            if (string.IsNullOrEmpty(targetFrameworks))
            {
                targetFrameworks = GetTargetFramework(projectPath);
            }

            var frameworksArr = targetFrameworks.Split(';');

            var result = new XElement("dependencies");

            foreach (var frmw in frameworksArr)
            {
                var formattedFramework = FormatTargetFremwork(frmw);
                var group = new XElement("group",
                                         new XAttribute("targetFramework", formattedFramework));
                foreach (var dep in projDependencies)
                {
                    group.Add(dep);
                }
                result.Add(group);
            }

            //if(result == null) throw new Exception("GetPackageDependenciesNetStandard failed! Couldn't find target frameworks");

            if (!File.Exists(projectPath))
            {
                return(null);
            }

            NuspecCreatorHelper.LoadProject(projectPath, out _, out var xmlns, out var project);

            var condPackRef = project.Elements(xmlns + "ItemGroup").Where(e => e.Attribute(xmlns + "Condition") != null)
                              .ToList();
            var nonCondPackRef = project.Elements(xmlns + "ItemGroup")
                                 .Where(e => e.Attribute(xmlns + "Condition") == null).Elements(xmlns + "PackageReference").ToList();

            foreach (var package in nonCondPackRef)
            {
                foreach (var group in result.Elements("group"))
                {
                    var dep = new XElement("dependency",
                                           new XAttribute("id", package.Attribute("Include")?.Value ?? string.Empty),
                                           new XAttribute("version", package.Attribute("Version")?.Value ?? string.Empty),
                                           new XAttribute("exclude", "Build,Analyzers"));
                    group.Add(dep);
                }
            }

            //result = GetMultiFrameworkDependenciesGroups(projectPath, result);
            AddConditionalPackages(condPackRef, result);

            return(result);

            void AddConditionalPackages(List <XElement> conditionalPackages, XElement res)
            {
                foreach (var cond in conditionalPackages)
                {
                    var frmwrk = cond.Attribute(xmlns + "Condition").Value;
                    frmwrk = frmwrk.Substring(frmwrk.LastIndexOf(" ") + 2).Trim('\'');
                    frmwrk = FormatTargetFremwork(frmwrk);
                    var grp = res.Elements(xmlns + "group")
                              .First(g => g.Attribute(xmlns + "targetFramework")?.Value == frmwrk);
                    var packages = cond.Elements().ToList();
                    foreach (var pck in packages)
                    {
                        var toDelete = grp.Elements(xmlns + "dependency")
                                       .FirstOrDefault(d =>
                                                       d.Attribute(xmlns + "id")?.Value == pck.Attribute(xmlns + "Include")?.Value);
                        toDelete?.Remove();

                        var version = pck.Attribute("Version")?.Value;
                        if (version != null)
                        {
                            grp.Add(
                                new XElement("dependency",
                                             new XAttribute("id", pck.Attribute("Include")?.Value ?? string.Empty),
                                             new XAttribute("version", version),
                                             new XAttribute("exclude", "Build,Analyzers")));
                        }
                    }
                }
            }
        }