构建失败.NET的核心应用由于缺少定义
我试图建立从CLI使用dotnet build
我的.NET的核心应用程序,但每一次我得到这个错误:构建失败.NET的核心应用由于缺少定义
'IConfigurationBuilder' does not contain a definition for 'AddEnvironmentVariables' and no extension method 'AddEnvironmentVariables' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)
这是我的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>();
}
看着this example我什么也看不到明显的错误与我Startup.cs
。
更新 我project.json
文件:
{
"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"
]
}
您需要Microsoft.Extensions.Configuration命名空间范围,以获取扩展方法。要么完全限定它,或添加到您的文件的顶部:
using Microsoft.Extensions.Configuration;
您还需要参考的NuGet Microsoft.Extensions.Configuration.EnvironmentVariables。
我试过Microsoft.Extensions.Configuration.EnvironmentVariables但没有运气。我已经从NuGet获得了Microsoft.Extensions.Configuration。我添加了Microsoft.Extensions.Configuration.UserSecrets 然后它工作。
要添加的正确包。 AddEnvironmentVariables()
是Microsoft.Extensions.Configuration.EnvironmentVariables
谢谢,它正在建设中。我认为这个软件包已经重新命名了,所以我没有看到它。核心软件包总是在不断变化。 –
@ barnacle.m请记住,源代码位于GitHub上,所以如果您有任何疑问,可以随时查看。 – mason