升级 Azure 搜索 .NET 管理 SDK 的版本Upgrading versions of the Azure Search .NET Management SDK

本文介绍了如何迁移到 Azure 搜索 .NET 管理 SDK(用于预配或取消预配搜索服务、调整容量以及管理 API 密钥)的各个连续版本。This article explains how to migrate to successive versions of the Azure Search .NET Management SDK, used to provision or deprovision search services, adjust capacity, and manage API keys.

管理 SDK 面向管理 REST API 的某个特定版本。Management SDKs target a specific version of the Management REST API. 有关概念和操作的详细信息,请参阅搜索管理 (REST)For more information about concepts and operations, see Search Management (REST).

版本Versions

SDK 版本SDK version 相应的 REST API 版本Corresponding REST API version 功能添加或行为变更Feature addition or behavior change
2.02.0 api-version=2019-10-01api-version=2019-10-01 可用性改进。Usability improvements. 针对列出查询密钥的中断性变更(GET 已停用)。Breaking change on List Query Keys (GET is discontinued).
1.01.0 api-version=2015-08-19api-version=2015-08-19 第一个版本First version

如何升级How to upgrade

  1. 按以下方式更新 Microsoft.Azure.Management.Search 的 NuGet 引用:使用 NuGet 包管理器控制台,或者在 Visual Studio 中右键单击项目引用,然后选择“管理 NuGet 程序包...”。Update your NuGet reference for Microsoft.Azure.Management.Search using either the NuGet Package Manager Console or by right-clicking on your project references and selecting "Manage NuGet Packages..." in Visual Studio.

  2. 在 NuGet 已下载新的程序包及其依赖项后,请重新生成项目。Once NuGet has downloaded the new packages and their dependencies, rebuild your project. 根据代码结构的不同,重新生成该项目可能会成功,如果成功则操作完成。Depending on how your code is structured, it may rebuild successfully, in which case you are done.

  3. 如果生成失败,则可能是因为已实现某些已更改的 SDK 接口(如出于单元测试目)。If your build fails, it could be because you've implemented some of the SDK interfaces (for example, for the purposes of unit testing), which have changed. 若要解决此问题,需要实现 BeginCreateOrUpdateWithHttpMessagesAsync 等更新的方法。To resolve this, you'll need to implement newer methods such as BeginCreateOrUpdateWithHttpMessagesAsync.

  4. 在修复了任何生成错误后,可以对应用程序进行更改,以利用新功能。After fixing any build errors, you can make changes to your application to take advantage of new functionality.

升级到 2.0Upgrade to 2.0

Azure 搜索 .NET 管理 SDK 的版本 2 是一个次要升级,因此更改代码所需要的工作量应该极少。SDK 的更改在严格意义上而言是为改进 SDK 本身可用性而做出的客户端更改。Version 2 of the Azure Search .NET Management SDK is a minor upgrade, so changing your code should require only minimal effort.The changes to the SDK are strictly client-side changes to improve the usability of the SDK itself. 包括以下更改:These changes include the following:

  • Services.CreateOrUpdate 及其异步版本现在会自动轮询预配 SearchService,且在服务预配完成后才返回。Services.CreateOrUpdate and its asynchronous versions now automatically poll the provisioning SearchService and do not return until service provisioning is complete. 因此,无需自己编写此类轮询代码。This saves you from having to write such polling code yourself.

  • 如果仍想手动轮询服务预配,可使用新的 Services.BeginCreateOrUpdate 方法或其异步版本之一。If you still want to poll service provisioning manually, you can use the new Services.BeginCreateOrUpdate method or one of its asynchronous versions.

  • 新方法 Services.Update 及其异步版本已添加到 SDK。New methods Services.Update and its asynchronous versions have been added to the SDK. 这些方法使用 HTTP PATCH 来支持服务的增量更新。These methods use HTTP PATCH to support incremental updating of a service. 例如,现在可以通过将 SearchService 实例传递到仅包含所需 partitionCountreplicaCount 属性的方法来缩放服务。For example, you can now scale a service by passing a SearchService instance to these methods that contains only the desired partitionCount and replicaCount properties. 仍支持调用 Services.Get、修改返回的 SearchService 并将其传递给 Services.CreateOrUpdate 这一旧方法,但该方法不再是必要的。The old way of calling Services.Get, modifying the returned SearchService, and passing it to Services.CreateOrUpdate is still supported, but is no longer necessary.

后续步骤Next steps

如果遇到问题,最适合发布问题的论坛是 Stack OverflowIf you encounter problems, the best forum for posting questions is Stack Overflow. 如果找到 Bug,可以在 Azure .NET SDK GitHub 存储库中提出问题。If you find a bug, you can file an issue in the Azure .NET SDK GitHub repository. 请务必使用“[search]”来标记问题标题。Make sure to label your issue title with "[search]".