在Startup.cs中添加AddOptions时出错 [英] Error while adding AddOptions in Startup.cs
问题描述
I am trying to implement options pattern as mentioned in this link - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration#options-example
当我在Startup.cs的ConfigureServices中添加这两行时
When I add these 2 lines in ConfigureServices of Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Setup options with DI
services.AddOptions();
services.Configure<AppSettingsModel>(Configuration);
在以下方法或属性错误之间,我得到以下调用是模棱两可的: 呼叫是模棱两可的错误屏幕截图
I get below call is ambiguous between the following methods or properties error- call is ambiguous error screenshot
我完整的project.json就是这样的>
My complete project.json is like this-
{
"dependencies": {
"Glimpse": "2.0.0-beta1",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Identity": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
"Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": {
"version": "1.0.0",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"net461": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config",
"Views",
"Areas/**/Views",
"appsettings.json"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
我的环境是-VS2015 update3,.net core SDK 1.0.0和Preview2工具
My environment is - VS2015 update3, .net core SDK 1.0.0 and preview2 tooling
我的项目模板是-ASP.NET核心应用程序(.NET Framework 4.6.1)
My project template is - ASP.NET core application (.NET framework 4.6.1)
有人可以指导我吗?
推荐答案
您必须从依赖项中删除Glimpse
.您可以在 NuGet 上看到,它取决于Glimpse.Server
和Glimpse.Server
依赖 Microsoft.AspNet.FileProviders.Embedded
,这是ASP.NET Core的过时软件包直到RC1版本.这些软件包现在被命名为Microsoft.AspNetCore.*
.
You have to remove Glimpse
from your dependencies. As you can see on NuGet it depends on Glimpse.Server
and Glimpse.Server
depends on Microsoft.AspNet.FileProviders.Embedded
which is an outdated package of ASP.NET Core until the RC1 version. The packages are now named Microsoft.AspNetCore.*
.
这将导致(旧程序集和新程序集)都被获取,并且编译器无法确定要使用哪个程序集.混合版本总是很糟糕.
This causes that both (old and new assemblies) get fetched and the compiler can't determine which one to use. Mixing versions is always very bad.
这篇关于在Startup.cs中添加AddOptions时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!