private List <NugetDependency> GetDependencies() { NuGet.PackageReferenceFile configFile = new NuGet.PackageReferenceFile(PackagesConfigPath); List <NuGet.PackageReference> packages = new List <NuGet.PackageReference>(configFile.GetPackageReferences()); var dependencies = new List <NugetDependency>(); foreach (var packageRef in packages) { string componentName = packageRef.Id; var version = new NuGet.Versioning.NuGetVersion(packageRef.Version.Version, packageRef.Version.SpecialVersion, packageRef.Version.Metadata); var versionRange = new NuGet.Versioning.VersionRange(version, true, version, true); NuGet.Frameworks.NuGetFramework framework = null; if (packageRef.TargetFramework != null) { try { framework = NuGet.Frameworks.NuGetFramework.Parse(packageRef.TargetFramework.FullName); } catch (Exception e) { Console.WriteLine("Unable to parse framework: " + packageRef.TargetFramework.FullName); } } var dep = new NugetDependency(componentName, versionRange, framework); dependencies.Add(dep); } return(dependencies); }
public List <string> CreateFlatList() { // Load the packages.config file into a list of Packages NuGet.PackageReferenceFile configFile = new NuGet.PackageReferenceFile(PackagesConfigPath); List <NuGet.PackageReference> packages = new List <NuGet.PackageReference>(configFile.GetPackageReferences()); BdioPropertyHelper bdioPropertyHelper = new BdioPropertyHelper(); List <string> externalIds = new List <string>(); foreach (NuGet.PackageReference packageReference in packages) { string externalId = bdioPropertyHelper.CreateNugetExternalId(packageReference.Id, packageReference.Version.ToString()); externalIds.Add(externalId); } return(externalIds); }
public BdioContent BuildBOM() { // Load the packages.config file into a list of Packages NuGet.PackageReferenceFile configFile = new NuGet.PackageReferenceFile(PackagesConfigPath); // Setup NuGet API // Snippets taken from https://daveaglick.com/posts/exploring-the-nuget-v3-libraries-part-2 with modifications List <Lazy <INuGetResourceProvider> > providers = new List <Lazy <INuGetResourceProvider> >(); providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support providers.AddRange(Repository.Provider.GetCoreV2()); // Add v2 API support // we may need more code here around handling package sources. PackageSource packageSource = new PackageSource(PackagesRepoUrl); SourceRepository sourceRepository = new SourceRepository(packageSource, providers); PackageMetadataResource packageMetadataResource = sourceRepository.GetResource <PackageMetadataResource>(); // Create BDIO BdioContent bdioContent = BuildBOMFromMetadata(new List <NuGet.PackageReference>(configFile.GetPackageReferences()), packageMetadataResource); return(bdioContent); }
public BdioContent BuildBOM() { // Load the packages.config file into a list of Packages NuGet.PackageReferenceFile configFile = new NuGet.PackageReferenceFile(PackagesConfigPath); // Setup NuGet API // Snippets taken from https://daveaglick.com/posts/exploring-the-nuget-v3-libraries-part-2 with modifications List <Lazy <INuGetResourceProvider> > providers = new List <Lazy <INuGetResourceProvider> >(); providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support providers.AddRange(Repository.Provider.GetCoreV2()); // Add v2 API support List <PackageMetadataResource> metadataResourceList = CreateMetaDataResourceList(providers); // Create BDIO BdioContent bdioContent = BuildBOMFromMetadata(new List <NuGet.PackageReference>(configFile.GetPackageReferences()), metadataResourceList); return(bdioContent); }