本文整理汇总了C#中SourceRepository.GetResource方法的典型用法代码示例。如果您正苦于以下问题:C# SourceRepository.GetResource方法的具体用法?C# SourceRepository.GetResource怎么用?C# SourceRepository.GetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceRepository
的用法示例。
在下文中一共展示了SourceRepository.GetResource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllVersionsForPackageId
/// <summary>
/// Get all versions for a specific package Id.
/// </summary>
/// <param name="sourceRepository"></param>
/// <param name="packageId"></param>
/// <param name="project"></param>
/// <param name="includePrerelease"></param>
/// <returns></returns>
public static IEnumerable<NuGetVersion> GetAllVersionsForPackageId(SourceRepository sourceRepository, string packageId, NuGetProject project, bool includePrerelease)
{
IEnumerable<string> targetFrameworks = GetProjectTargetFrameworks(project);
SearchFilter searchfilter = new SearchFilter();
searchfilter.IncludePrerelease = includePrerelease;
searchfilter.SupportedFrameworks = targetFrameworks;
searchfilter.IncludeDelisted = false;
PSSearchResource resource = sourceRepository.GetResource<PSSearchResource>();
PSSearchMetadata result = null;
IEnumerable<NuGetVersion> allVersions = Enumerable.Empty<NuGetVersion>();
try
{
Task<IEnumerable<PSSearchMetadata>> task = resource.Search(packageId, searchfilter, 0, 30, CancellationToken.None);
result = task.Result
.Where(p => string.Equals(p.Identity.Id, packageId, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault();
allVersions = result.Versions;
}
catch (Exception)
{
if (result == null || !allVersions.Any())
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
Resources.UnknownPackage, packageId));
}
}
return result.Versions;
}