"IConfiguration"不包含"Get"的定义 [英] 'IConfiguration' does not contain a definition for 'Get'
问题描述
最初,我在1.0.0-rc1-beta6中有代码.
公共静态IConfiguration配置{get;放;}公共启动(IHostingEnvironment env,IApplicationEnvironment appEnv){//设置配置源.var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath).AddJsonFile("config.json").AddEnvironmentVariables();配置= builder.Build();var test = Configuration.Get("ASPNET_ENV");}
现在我要使用1.0.0-rc1-update,代码是:
公共启动(IHostingEnvironment env,IApplicationEnvironment appEnv){//设置配置源.var builder = new ConfigurationBuilder().SetBasePath(appEnv.ApplicationBasePath).AddJsonFile("config.json").AddEnvironmentVariables();配置= builder.Build();var test = Configuration.Get("ASPNET_ENV");}
"ASP.NET_ENV";来自launchSettings.json文件.
"profiles":{"IIS Express":{" commandName" ;:" IISExpress" ;,"launchBrowser":是的,"environmentVariables":{"ASPNET_ENV":开发"},"sdkVersion":"dnx-clr-win-x64.1.0.0-beta6".},
但是我仍然在最后一行收到错误消息.
'IConfiguration'不包含'Get'的定义,最佳扩展方法重载'SessionExtensions.Get(ISession,string)'需要类型为'ISession'的接收器.
也在这里得到错误.
公共无效的ConfigureServices(IServiceCollection服务){//将MVC服务添加到服务容器.services.AddMvc();//错误}
我的project.json文件
<代码> {"webroot":"wwwroot",版本":"1.0.0- *",依赖项":{"Microsoft.AspNet.Diagnostics":"1.0.0-rc1-final","Microsoft.AspNet.Mvc":"6.0.0-rc1-final","Microsoft.AspNet.Mvc.TagHelpers":"6.0.0-rc1-final","Microsoft.AspNet.Server.IIS":"1.0.0-beta7","Microsoft.AspNet.Server.WebListener":"1.0.0-rc1-final","Microsoft.AspNet.StaticFiles":"1.0.0-rc1-final","Microsoft.AspNet.Tooling.Razor":"1.0.0-rc1-final","Microsoft.Framework.Configuration.Json":"1.0.0-beta8","Microsoft.Framework.Logging":"1.0.0-beta8","Microsoft.Framework.Logging.Console":"1.0.0-beta8","Microsoft.VisualStudio.Web.BrowserLink.Loader":"14.0.0-rc1-final","EntityFramework":"6.1.3","jqGridWebApi":"1.1.4","EnyimMemcached":"2.13.0","xunit":"2.2.0-beta1-build3239","Moq":"4.2.1510.2205","NLog":"2.1.0&","CryptSharpOfficial":"2.1.0&","System.Linq.Dynamic":"1.0.4";"System.Linq.Dynamic":"1.0.4"},命令":{"web":"Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001","kestrel":"Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5005"},框架":{"dnx451":{"frameworkAssemblies":{"System.configuration":"4.0.0.0","System.Data":"4.0.0.0";}}},排除":["wwwroot","node_modules","bower_components"],"publishExclude":["node_modules","bower_components","**.xproj","**.user","**.vspscc"],脚本":{预发布":["npm install","bower安装","gulp clean","gulp min".]},配置":{登台":{}}}
安装NuGet软件包:
Microsoft.Extensions.Configuration.Binder
重复:
Originally, I had the code in 1.0.0-rc1-beta6.
public static IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
var test = Configuration.Get("ASPNET_ENV");
}
Now I want to use 1.0.0-rc1-update, the code is:
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
var test = Configuration.Get("ASPNET_ENV");
}
"ASP.NET_ENV" is from launchSettings.json file.
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNET_ENV": "Development"
},
"sdkVersion": "dnx-clr-win-x64.1.0.0-beta6"
},
But I still get the error on the last line.
'IConfiguration' does not contain a definition for 'Get' and the best extension method overload 'SessionExtensions.Get(ISession, string)' requires a receiver of type 'ISession'.
Also get the error here.
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc(); //error
}
My project.json file
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
"Microsoft.Framework.Logging": "1.0.0-beta8",
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"EntityFramework": "6.1.3",
"jqGridWebApi": "1.1.4",
"EnyimMemcached": "2.13.0",
"xunit": "2.2.0-beta1-build3239",
"Moq": "4.2.1510.2205",
"NLog": "2.1.0",
"CryptSharpOfficial": "2.1.0",
"System.Linq.Dynamic": "1.0.4"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5005"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.configuration": "4.0.0.0",
"System.Data": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
},
"configurations": {
"Staging": { }
}
}
Install the NuGet package:
Microsoft.Extensions.Configuration.Binder
Duplicate: Bind a IConfigurationSection to an complex object without aspnetcore
这篇关于"IConfiguration"不包含"Get"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!