在ASP.NET Core 2.0中找不到AddJsonOptions

Sup*_*JMN 9 .net c# asp.net asp.net-core

我正在将我的ASP.NET 1.1项目迁移到2.0:

Setup类中,在Configure方法覆盖下我有:

services.AddMvc()
    .AddJsonOptions(options =>
        options.SerializerSettings.Converters.Add(new StringEnumConverter())
    );
Run Code Online (Sandbox Code Playgroud)

AddJsonOptions方法缺失.

这是怎么回事?我怎样才能获得相同的功能?

Set*_*Set 15

AddJsonOptionsMicrosoft.AspNetCore.Mvc.Formatters.Json nuget包中定义.

如果您的项目依赖于Microsoft.AspNetCore.Allmetapackage(在.csproj中<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0"/>),那么您已经拥有它.否则,您可能需要直接添加该包.

之后:

  • dotnet restore
  • 检查一下 using Microsoft.Extensions.DependencyInjection;