我正在尝试使用 CLI 构建我的 .NET Core 应用程序dotnet build
,但每次我都会收到此错误:
“IConfigurationBuilder”不包含“AddEnvironmentVariables”的定义,并且找不到接受“IConfigurationBuilder”类型的第一个参数的扩展方法“AddEnvironmentVariables”(您是否缺少 using 指令或程序集引用?)
这是我的ConfigureServices
中的方法Startup.cs
问题发生的地方:
public void ConfigureServices(IServiceCollection services)
{
var builder = new ConfigurationBuilder()
.AddJsonFile("config.json")
.AddEnvironmentVariables()
.Build();
services.AddEntityFrameworkSqlServer()
.AddDbContext<MyContext>(options =>
options.UseSqlServer(builder["Data:MyContext:ConnectionString"]));
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<MyContext>()
.AddDefaultTokenProviders()
.AddOpenIddictCore<Application>(config => config.UseEntityFramework());
services.AddMvc();
services.AddScoped<OpenIddictManager<ApplicationUser, Application>, CustomOpenIddictManager>();
}
看着这个例子 https://github.com/openiddict/openiddict-core/blob/dev/samples/Mvc.Server/Startup.cs我没有发现我的明显问题Startup.cs
.
Update
My project.json
file:
{
"compilationOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"dependencies": {
"AspNet.Security.OAuth.Validation": "1.0.0-alpha1-*",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-*",
"Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc2-*",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-*",
"OpenIddict.Core": "1.0.0-*",
"OpenIddict.EF": "1.0.0-*"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel": { "type": "build" }
}
},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-*"
}
},
"imports": [
"dnxcore50",
"portable-net451+win8"
]
}
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-rc2-*",
"imports": "portable-net45+wp80+win8+wpa81+dnxcore50"
}
},
"scripts": {
"postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
},
"content": [
"wwwroot",
"Views",
"config.json",
"web.config"
],
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
2018 年 10 月更新:在 VS 2017 的最新版本中创建新的 .NET Core 2.1 应用程序时,不会出现此问题。自从我提出这个问题以来,一切现在都处于长期稳定的版本。