public PackageVersionVariable Update(string variableName, string version) { if (!_versionVariables.TryGetValue(variableName, out var variable)) { var element = _document.CreatePropertyElement(variableName); variable = new PackageVersionVariable(element, version, isReadOnly: false); _versionVariables[variableName] = variable; variable.AddToGroup(_autoPackageVersions); } variable.UpdateVersion(version); return(variable); }
public PackageVersionVariable AddPinnedVariable(string variableName, string version) { if (_versionVariables.ContainsKey(variableName)) { throw new InvalidOperationException("Key already exists: " + variableName); } var element = _document.CreatePropertyElement(variableName); var variable = new PackageVersionVariable(element, version, isReadOnly: true); _versionVariables.Add(variableName, variable); variable.AddToGroup(_pinnedPackageVersions); return(variable); }
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); }