nuget - NuGet Gallery 搜索索引应何时更新?

标签 nuget nuget-server nugetgallery

我最近根据 GitHub 上的说明安装了本地 NuGet 库.

当我通过 UI 上传包时,它似乎工作正常,但使用命令行推送的包不会显示在搜索结果中。在程序包窗口中,它显示“搜索索引上次更新时间为 55 分钟前”。这对应于我上次发布网站的时间。什么决定了搜索索引何时运行?快速浏览一下代码,它看起来就像您添加/删除包时应该发生的那样,但它似乎并没有这样做。

如何提高索引频率?

最佳答案

在 NuGetGallery 项目中,转到 CreatePackageInternal /Controllers/ApiController 中的方法并在 return 之前调用此行声明。

IndexingService.UpdateIndex(true);

你的代码必须是这样的

    private async Task<ActionResult> CreatePackageInternal()
    {
        // Get the user
        var user = GetCurrentUser();

        using (var packageToPush = ReadPackageFromRequest())
        {
            if (packageToPush.Metadata.MinClientVersion > typeof(Manifest).Assembly.GetName().Version)
            {
                return new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, String.Format(
                    CultureInfo.CurrentCulture,
                    Strings.UploadPackage_MinClientVersionOutOfRange,
                    packageToPush.Metadata.MinClientVersion));
            }

            // Ensure that the user can push packages for this partialId.
            var packageRegistration = PackageService.FindPackageRegistrationById(packageToPush.Metadata.Id);
            if (packageRegistration != null)
            {
                if (!packageRegistration.IsOwner(user))
                {
                    return new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.ApiKeyNotAuthorized);
                }

                // Check if a particular Id-Version combination already exists. We eventually need to remove this check.
                string normalizedVersion = packageToPush.Metadata.Version.ToNormalizedString();
                bool packageExists =
                    packageRegistration.Packages.Any(
                        p => String.Equals(
                            p.NormalizedVersion,
                            normalizedVersion,
                            StringComparison.OrdinalIgnoreCase));

                if (packageExists)
                {
                    return new HttpStatusCodeWithBodyResult(
                        HttpStatusCode.Conflict,
                        String.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified,
                                      packageToPush.Metadata.Id, packageToPush.Metadata.Version.ToNormalizedStringSafe()));
                }
            }

            var package = PackageService.CreatePackage(packageToPush, user, commitChanges: false);
            AutoCuratePackage.Execute(package, packageToPush, commitChanges: false);
            EntitiesContext.SaveChanges();

            using (Stream uploadStream = packageToPush.GetStream())
            {
                await PackageFileService.SavePackageFileAsync(package, uploadStream);
            }
        }

        IndexingService.UpdateIndex(true);

        return new HttpStatusCodeResult(HttpStatusCode.Created);
    }

关于nuget - NuGet Gallery 搜索索引应何时更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26885663/

相关文章:

javascript - 如何在示例 MathJax 上正确使用 ASP.Net Core 项目中的 JavaScript NuGet 库?

visual-studio - 当简单的共享文件夹运行良好时,NuGet 自托管 : why bother with a Nuget. 服务器

asp.net - NuGet 服务器 - 基于动态 Feed URL 访问自定义私有(private) NuGet 库

reference - 如何在 Visual Studio 2013 中访问 NuGet 包管理器?

c# - NuGet - 此包尚未编入索引。它将出现在搜索结果中,并且在索引完成后可用于安装/恢复

package - NuGet 提要托管选项,包括 MyGet

nuget-server - 发布到 ProGet 但我看不到任何包

nuget - 如何使用 Nuget.Core 获取预发布包列表?

c# - Msbuild v15 无法解析 nuspec 文件的元数据变量