首页 > 其他分享 >nuget search v3 linq

nuget search v3 linq

时间:2024-05-27 23:15:27浏览次数:25  
标签:NuGet search Console nuget v3 WriteLine using var new

https://github.com/yanckst/search-nuget-v3/blob/master/search.linq

<Query Kind="Program">
  <NuGetReference>NuGet.PackageManagement</NuGetReference>
  <NuGetReference>NuGet.Packaging</NuGetReference>
  <Namespace>System.Threading.Tasks</Namespace>
  <Namespace>NuGet.Protocol.Core.Types</Namespace>
  <Namespace>NuGet.Configuration</Namespace>
  <Namespace>NuGet.ProjectManagement</Namespace>
  <Namespace>NuGet.PackageManagement</Namespace>
</Query>

NuGet.Protocol.Core.Types.SourceRepository sourceRepository;

async Task Main()
{
    InitializeNugetDependencies();
    var jsonNugetPackages = await SearchTestPackage("Newtonsoft.Json");
    jsonNugetPackages.Dump();
}

private void InitializeNugetDependencies() 
{
    List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
    providers.AddRange(Repository.Provider.GetCoreV3());

    PackageSource packageSource = new PackageSource("https://api.nuget.org/v3/index.json");
    this.sourceRepository = new NuGet.Protocol.Core.Types.SourceRepository(packageSource, providers);
}


private async Task<IEnumerable<IPackageSearchMetadata>> SearchTestPackage(string packageName)
{
    var searchResource = await this.sourceRepository.GetResourceAsync<PackageSearchResource>();
    var supportedFramework = new[] { ".NETFramework,Version=v4.6" };
    var searchFilter = new SearchFilter(true)
    {
        SupportedFrameworks = supportedFramework,
        IncludeDelisted = false
    };

    return await searchResource.SearchAsync(packageName, searchFilter, 0, 10, null, CancellationToken.None);
}

 

 

C# 调用NuGet 实现获取包的顶级依赖

 https://www.cnblogs.com/smartisn/p/16026342.html  
using System;
using static NuGet.Frameworks.FrameworkConstants;
using static NuGet.Protocol.Core.Types.Repository;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Packaging.Core;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
//using NuGet.Test.Utility;
using NuGet.Versioning;
using NuGet.PackageManagement;
namespace NuGet_Remote_develop
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("!!!!");
            // Set up
            var packageIdentityA100 = new PackageIdentity("a", NuGetVersion.Parse("1.0.0"));
            Console.WriteLine("%%%%%");
            var packageIdentityB100 = new PackageIdentity("b", NuGetVersion.Parse("1.0.0"));
            var packageIdentityC100 = new PackageIdentity("c", NuGetVersion.Parse("1.0.0"));
            var packageIdentityC110 = new PackageIdentity("c", NuGetVersion.Parse("1.1.0"));
            var packageIdentityD100 = new PackageIdentity("d", NuGetVersion.Parse("1.0.0"));


            var packageDependencyInfos = new List<PackageDependencyInfo>();
            //制造关于A的依赖图
            var packageDependencyInfoA = new PackageDependencyInfo(packageIdentityA100,
                new PackageDependency[] {
                    new PackageDependency(packageIdentityB100.Id, VersionRange.Parse(packageIdentityB100.Version.OriginalVersion)),
                    new PackageDependency(packageIdentityC100.Id, VersionRange.Parse(packageIdentityC100.Version.OriginalVersion)),
                });
            var packageDependencyInfoB = new PackageDependencyInfo(packageIdentityB100,
                new PackageDependency[] {
                    new PackageDependency(packageIdentityD100.Id, VersionRange.Parse(packageIdentityD100.Version.OriginalVersion)),
                });
            var packageDependencyInfoC = new PackageDependencyInfo(packageIdentityC110, Enumerable.Empty<PackageDependency>());
            var packageDependencyInfoD = new PackageDependencyInfo(packageIdentityD100, Enumerable.Empty<PackageDependency>());

            //增加所有的依赖关系图
            packageDependencyInfos.Add(packageDependencyInfoA);
            packageDependencyInfos.Add(packageDependencyInfoB);
            packageDependencyInfos.Add(packageDependencyInfoC);
            packageDependencyInfos.Add(packageDependencyInfoD);

            // Act————》》获取依赖图
            var packageWithDependants = PackageGraphAnalysisUtilities.GetPackagesWithDependants(packageDependencyInfos);
            Console.WriteLine(packageWithDependants);
            Console.WriteLine("*****");
            foreach (var package in packageWithDependants)
            {
                switch (package.Identity.Id)
                {
                    case "a":
                        {
                            //看他是不是没有其他的依赖项
                            Console.WriteLine(package.DependantPackages.Count);
                            Console.WriteLine(package.IsTopLevelPackage);
                            break;
                        }
                    case "b":
                        {
                            //看他是不是只有一个依赖项,而且这个依赖项是A。并且他不是直接依赖
                            Console.WriteLine( package.DependantPackages.Count);
                            Console.WriteLine(package.DependantPackages.Single().Id);
                            Console.WriteLine(package.IsTopLevelPackage);
                            break;
                        }
                    case "c":
                        {
                            Console.WriteLine(package.DependantPackages.Count);
                            Console.WriteLine(package.IsTopLevelPackage);
                            break;
                        }
                    case "d":
                        {
                            Console.WriteLine( package.DependantPackages.Count);
                            Console.WriteLine( package.DependantPackages.Single().Id);
                            Console.WriteLine(package.IsTopLevelPackage);
                            break;
                        }
                    default:
                        {
                            Console.WriteLine($"Unexpected package {package.Identity}");
                            break;
                        }
                }
            }
            Console.ReadKey();
        }
    }
}

 

标签:NuGet,search,Console,nuget,v3,WriteLine,using,var,new
From: https://www.cnblogs.com/webenh/p/18216789

相关文章

  • Linux用docker安装Elasticsearch&&SpringBoot整合ES
    一. 部署Elasticsearch1.docker查询docker容器中的esdockersearchelasticsearch2. 安装(PS:查看自己的springBoot的版本号 对应的es版本安装)dockerpullelasticsearch:7.6.23.查看已安装的docker镜像dockerimages4.创建挂在目录mkdir-p/data/elk/es/{......
  • 搜索引擎ElasticSearch18_Spring Data ElasticSearch 使用6
    一、SpringDataElasticSearch简介1、什么是SpringDataSpringData是一个用于简化数据库访问,并支持云服务的开源框架。其主要目标是使得对数据的访问变得方便快捷,并支持map-reduce框架和云计算数据服务。SpringData可以极大的简化JPA的写法,可以在几乎不用写实现的情况......
  • Elasticsearch Guide 7.17
    目录介绍扩展性与可恢复性clientSetupElasticsearchInstallingESConfiguringESImportantsystemconfigurationBootstrapChecksBootstrapChecksforX-PackStartingElasticsearchStoppingElasticsearchDiscoveryandclusterformationAddandremovenodesinyourclust......
  • 搜索引擎ElasticSearch18_ElasticSearch编程操作5
    一、创建工程,导入坐标pom.xml坐标<dependencies><dependency><groupId>org.elasticsearch</groupId><artifactId>elasticsearch</artifactId><version>5.6.8</version></dependency>......
  • .Net使用ElasticSearch原理及入门
    1、Elasticsearch简介Elasticsearch是一个基于Lucene,开源的高扩展分布式全文检索引擎,它不会将信息储存为列数据行,而是储存已序列化为JSON文档的复杂数据结构。当文档被储存时,它将建立索引并且近实时(1s)被搜索。Elasticsearch使用一种被称为倒排索引的数据结构,该结构支持快......
  • 铭飞CMS-search接口存在sql注入漏洞
    漏洞描述铭飞CMS是一款开源的内容管理系统,SQL注入漏洞存在于铭飞CMS的search接口处,当用户输入的内容未被充分过滤或转义时,攻击者可以在url中构造嵌入恶意的SQL语句,从而实现对数据库的操控fofabody="铭飞MCMS"||body="/mdiy/formData/save.do"||body="static/plugins/ms/1.0......
  • Elasticsearch集群和Logstash、Kibana部署
    1、Elasticsearch集群部署服务器安装软件主机名IP地址系统版本配置ElasticsearchElk10.3.145.14centos7.5.18042核4GElasticsearchEs110.3.145.56centos7.5.18042核3GElasticsearchEs210.3.145.57centos7.5.18042核3G软件版本:elasticsearch-7.13.2.tar.gz示例节点:10.3......
  • YOLOv8 更换骨干网络之 MobileNetV3 详解
    鱼弦:公众号【红尘灯塔】,CSDN博客专家、内容合伙人、新星导师、全栈领域优质创作者、51CTO(Top红人+专家博主)、github开源爱好者(go-zero源码二次开发、游戏后端架构https://github.com/Peakchen)YOLOv8更换骨干网络之MobileNetV3详解1.MobileNetV3简介MobileNetV3......
  • elasticsearch入门介绍
    一、介绍1.1ES简介Elasticsearch(简称ES)是使用iava开发,基于Lucene、分布式、通过Restful7方式进行交互的近实时搜索平台框架。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。ES是ELK架构技术栈的组件之一。ELK(ES+Logs......
  • elasticsearch使用Sort排序时Please use a keyword field instead.
    具体报错信息ElasticsearchStatusException[Elasticsearchexception[type=search_phase_execution_exception,reason=allshardsfailed]];nested:ElasticsearchException[Elasticsearchexception[type=illegal_argument_exception,reason=Textfieldsarenotoptimised......