Skip to content

Instantly share code, notes, and snippets.

@Eonasdan
Created December 31, 2016 04:06
Show Gist options
  • Select an option

  • Save Eonasdan/095c33bf0b0f27b0a73ab0d05e17b2f6 to your computer and use it in GitHub Desktop.

Select an option

Save Eonasdan/095c33bf0b0f27b0a73ab0d05e17b2f6 to your computer and use it in GitHub Desktop.
parsing package.config for nuget package explorer
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class packages
{
private packagesPackage[] packageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("package")]
public packagesPackage[] package
{
get
{
return this.packageField;
}
set
{
this.packageField = value;
}
}
}
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class packagesPackage
{
private string idField;
private string versionField;
private string targetFrameworkField;
private bool developmentDependencyField;
private bool developmentDependencyFieldSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string id
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string targetFramework
{
get
{
return this.targetFrameworkField;
}
set
{
this.targetFrameworkField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public bool developmentDependency
{
get
{
return this.developmentDependencyField;
}
set
{
this.developmentDependencyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool developmentDependencySpecified
{
get
{
return this.developmentDependencyFieldSpecified;
}
set
{
this.developmentDependencyFieldSpecified = value;
}
}
}
var packageMetadataDependencySets = viewModel.PackageMetadata.DependencySets;
var packages = new XmlSerializer(typeof(packages)).Deserialize(new XmlTextReader(PathToConfig)) as packages;
//tries to match a target framework with an existing group
var packageDependencySet = packageMetadataDependencySets.First(x => packages.package.First()
.targetFramework.Contains($"{x.TargetFramework.FullName.Replace($"{x.TargetFramework.Identifier},Version=v", "net").Replace(".", "")}"))
?? packageMetadataDependencySets.First();
var parsedPackages = packages.package.Select(package => new PackageDependency(package.id, new VersionSpec(SemanticVersion.Parse(package.version)), null)).ToList();
packageMetadataDependencySets.Add(new PackageDependencySet(packageDependencySet.TargetFramework, parsedPackages));
_dependencySets = packageMetadataDependencySets;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment