public static bool TryLoad(string sourceFile, out DependencyVersionsFile file)
 {
     try
     {
         file = Load(sourceFile);
         return(true);
     }
     catch
     {
         file = null;
         return(false);
     }
 }
        public static DependencyVersionsFile LoadFromProject(Project project)
        {
            var file = new DependencyVersionsFile(ProjectRootElement.Create(NewProjectFileOptions.None));

            foreach (var property in project.AllEvaluatedProperties.Where(p => p.Xml != null))
            {
                var group      = (ProjectPropertyGroupElement)property.Xml.Parent;
                var isReadOnly = string.Equals(group.Label, PinnedPackageVersionsLabel, StringComparison.OrdinalIgnoreCase);

                var variable = new PackageVersionVariable(property.Xml, property.EvaluatedValue?.Trim(), isReadOnly);
                file._versionVariables[property.Name] = variable;
            }

            file.EnsureGroupsCreated();

            return(file);
        }
        public static DependencyVersionsFile Load(ProjectRootElement document)
        {
            var file = new DependencyVersionsFile(document);

            var propGroups = file._document.PropertyGroups;

            var listPropertyGroups = new List <ProjectPropertyGroupElement>();

            foreach (var propGroup in propGroups)
            {
                var attr = propGroup.Label;
                if (attr != null && attr.StartsWith(PackageVersionsLabel, StringComparison.OrdinalIgnoreCase))
                {
                    file.HasVersionsPropertyGroup = true;
                    listPropertyGroups.Add(propGroup);
                }
            }

            foreach (var group in listPropertyGroups)
            {
                var isReadOnly = string.Equals(group.Label, PinnedPackageVersionsLabel, StringComparison.OrdinalIgnoreCase);
                if (isReadOnly)
                {
                    file._pinnedPackageVersions = group;
                }
                else
                {
                    file._autoPackageVersions = group;
                }

                foreach (var child in group.Properties)
                {
                    var variable = new PackageVersionVariable(child, isReadOnly);
                    file._versionVariables[variable.Name] = variable;
                }
            }

            file.EnsureGroupsCreated();
            return(file);
        }