ASPNET Core pre-RC2 依赖性歧义

ASPNET Core pre-RC2 dependency ambiguity

我正在使用:

.NET Command Line Tools (1.0.0-rc2-002439)

Product Information:
Version:     1.0.0-rc2-002439
Commit Sha:  ef0c3b2cee

Runtime Environment:
OS Name:     Windows
OS Version:  10.0.10586
OS Platform: Windows
RID:         win10-x64

并获得:

error CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)' and 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)'

我怀疑 "dotnet restore" 中包含多个 OptionsModel 程序集(不同版本)。

证明可能在这里:

具有不同参数名称的第二个建议:

Project.lock.json 文件有几行有趣的内容("Infrastructure" 是引用程序集):

"Infrastructure/1.0.0": {
    "type": "project",
    "framework": ".NETFramework,Version=v4.6.1",
    "dependencies": {
      "Domain": "1.0.0",
      "Microsoft.Extensions.Caching.Abstractions": "1.0.0",
      "Microsoft.Extensions.OptionsModel": "1.0.0",
      "Newtonsoft.Json": "8.0.3",
      "WindowsAzure.Storage": "6.2.1"
    },
    "compile": {
      "net461/Infrastructure.dll": {}
    },
    "runtime": {
      "net461/Infrastructure.dll": {}
    }
  }

而 Web 应用程序使用 Microsoft.Extensions.OptionsModel/1.0.0-rc2-15914

这里是基础架构组件的配置部分:

"dependencies": {
    "Domain": "1.0.0-*",
    "Microsoft.Extensions.Caching.Abstractions": "1.0.0-*",
    "Microsoft.Extensions.OptionsModel": "1.0.0-*",
    "Newtonsoft.Json": "8.0.3",
    "WindowsAzure.Storage": "6.2.1-*"
}

问题是:为什么执行时选择了不同的版本(1.0.0和1.0.0-rc2-15914)"dotnet restore"?

更新:我尝试将基础设施项目的 project.json 更改为 "Microsoft.Extensions.OptionsModel": "1.0.0-rc2-15914" 但由于屏幕截图中显示的歧义,我仍然无法编译。我的计算机上是否缓存了任何程序集?

解决方法是:

Microsoft.Extensions.Options 而不是 Microsoft.Extensions.Options 必须在引用的项目中使用模型包。