获取错误
以下方法或属性之间的调用不明确:'Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseConfiguration(Microsoft.AspNetCore.Hosting.IWebHostBuilder,Microsoft.Extensions.Configuration.IConfiguration)'和'Microsoft.AspNetCore.Hosting。 HostingAbstractionsWebHostBuilderExtensions.UseConfiguration
在.UseConfiguration(ConfigurationRoot)
行
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings-{Environment.GetEnvironmentVariable("azure")}.json")
.AddEnvironmentVariables()
.AddCommandLine(args);
ConfigurationRoot = builder.Build();
var application = new WebHostBuilder()
.UseConfiguration(ConfigurationRoot)
.UseIISIntegration()
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
.UseStartup<Startup>()
.Build();
application.Run();
{
"version": "1.0.0-*",
"description": "Aps.ManageIT.WebAPI",
"authors": [ "IPPCS" ],
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"copyToOutput": {
"include": [ "wwwroot" ],
"includeFiles": [
"appsettings.json",
"appsettings-dev.json",
"web.config",
"appsettings-aps.json",
"appsettings-adidasdev.json",
"appsettings-prod.json"
]
},
"compile": [
"wwwroot"
]
},
"publishOptions": {
"include": [ "wwwroot" ],
"includeFiles": [
"appsettings.json",
"appsettings-dev.json",
"web.config",
"appsettings-aps.json",
"appsettings-adidasdev.json",
"appsettings-prod.json"
]
},
"dependencies": {
"Aps.ManageIT.Repository.MongoDB": "1.0.0-*",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-final",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
"OpenIddict": "1.0.0-alpha2-0288",
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc2-final",
"Microsoft.Extensions.Options": "1.0.0-rc2-final",
"mongocsharpdriver": "2.2.0",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
"HtmlAgilityPack": "1.4.9.4",
"Microsoft.AspNet.WebApi.Cors": "5.2.3",
"Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
"Aps.JobIT.Log.Repository.MongoDB": "1.0.0-*",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-rc2-final",
"WindowsAzure.Storage": "8.0.1"
},
"frameworks": {
"net452": {}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"scripts": {
"postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
}
}
答案 0 :(得分:0)
首先,您引用的软件包是旧的预发布软件包。将您的软件包更新为稳定版本。
在1.0.0版本之前,已将此扩展方法从WebHostBuilderExtensions
移至.Abstractions
进行了更改。您使用的预发布包在两个位置都定义了此扩展,这就是您看到此错误的原因。更新到已发布的(1.0.0+)软件包时应解决此问题。
或者,使用完整的Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions.UseConfiguration(webHostBuilder, configuration)
方法,而不是通过扩展方法链接配置方法调用:
var webHostBuilder = new WebHostBuilder();
var application = Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions.UseConfiguration(webHostBuilder, ConfigurationRoot)
.UseIISIntegration()
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
.UseStartup<Startup>()
.Build();
application.Run();