【问题标题】:What is the NuGet API to help select a given Nuget package target framework that matches the best the given project target framework?什么是帮助选择与给定项目目标框架最佳匹配的给定 Nuget 包目标框架的 NuGet API?
【发布时间】:2020-11-13 02:21:17
【问题描述】:

给定一个项目目标框架(比如 net472)和一个包含一堆受支持目标框架的 nuget 包,我们可以使用什么 NuGet API 来将 Nuget 目标框架与项目目标框架匹配?

例如System.Diagnostics.DiagnosticSource 的包中有 5 个目标框架:

  • net45
  • net46
  • netstandard1.1
  • netstandard1.3
  • portable-net45+win8+wpa81

我想要 Nuget 自己在决定将任何这些框架与 net472 匹配时使用的相同 NuGet Api(我认为它会是 net46)。

由于搜索中存在大量误报,因此很难找到任何文档。

编辑 1

我发现它是 NuGet.Frameworks 包。现在正在寻找合适的 API...

【问题讨论】:

    标签: c# nuget


    【解决方案1】:

    这是我在一天结束时所拥有的:

    public class FrameworkFromLibFolderPath : IFrameworkSpecific
    {
        public FrameworkFromLibFolderPath(string libFolderPath)
        {
            LibFolderPath = libFolderPath;
            TargetFramework = NuGetFramework.ParseFolder(Path.GetFileName(libFolderPath));
        }
    
        public readonly string LibFolderPath;
    
        public NuGetFramework TargetFramework { get; }
    }
    

    var packageFrameworks = Directory
        .EnumerateDirectories(baseLibFolderPath)
        .Select(libFolderPath => new FrameworkFromLibFolderPath(libFolderPath))
        .ToList();
    var path = packageFrameworks.Count > 0 ? packageFrameworks.GetNearest(framework).LibFolderPath : baseLibFolderPath;
    

    【讨论】:

      猜你喜欢
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2012-02-27
      • 2018-11-15
      • 1970-01-01
      • 2018-11-01
      • 1970-01-01
      相关资源
      最近更新 更多