ASP.Net5 Startup.cs ConfigurationBuilder [英] ASP.Net5 Startup.cs ConfigurationBuilder

查看:1516
本文介绍了ASP.Net5 Startup.cs ConfigurationBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VS 2015年MVC的测试版8,我收到以下错误

 严重code描述项目文件行
错误CS1503参数1:不能从'字符串'到'Microsoft.Framework.Configuration.IConfigurationProviderNewInventory.DNX核心5.0˚F转换:\\项目\\ NewInventory的\\ src \\ NewInventory \\ Startup.cs 35

从我startup.cs的这一部分:

 公共启动(IHostingEnvironment ENV,IApplicationEnvironment appEnv)
        {
            //设置配置资源。            VAR建设者=新ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile(config.json)
                .AddJsonFile($配置{} env.EnvironmentName以.json,可选的:真正的);            如果(env.IsDevelopment())
            {
                //这个读取来自秘专卖店的配置项。
                //有关使用用户秘专卖店看到http://go.microsoft.com/fwlink/?LinkID=532709更多详情
                builder.AddUserSecrets();
            }
            builder.AddEnvironmentVariables();
            配置= builder.Build();
        }

当我将鼠标悬停在ConfigurationBuilder我可以看到它找'ConfigurationBuilder.ConfigurationBuilder(PARAMS IConfigurationProvider []提供商)

我要如何改变appEnv.ApplicationBasePath到IConfigurationProvider阵列?

我project.json是:

  {
  根目录:wwwroot的
  userSecretsId:aspnet5-NewInventory-f5a8bab7-e95b-485B-97e9-9a072438b107,
  版本:1.0.0- *,  依赖:{
    EntityFramework.SqlServer:7.0.0-beta5的,
    EntityFramework.Commands:7.0.0-beta5的,
    Microsoft.AspNet.Mvc:6.0.0-beta8,
    Microsoft.AspNet.Mvc.TagHelpers:6.0.0-beta5的,
    Microsoft.AspNet.Authentication.Cookies:1.0.0-beta5的
    Microsoft.AspNet.Authentication.Facebook:1.0.0-beta5的
    Microsoft.AspNet.Authentication.Google:1.0.0-beta5的
    Microsoft.AspNet.Authentication.MicrosoftAccount:1.0.0-beta5的
    Microsoft.AspNet.Authentication.Twitter:1.0.0-beta5的
    Microsoft.AspNet.Diagnostics:1.0.0-beta5的
    Microsoft.AspNet.Diagnostics.Entity:7.0.0-beta5的,
    Microsoft.AspNet.Identity.EntityFramework:3.0.0-beta8,
    Microsoft.AspNet.Server.IIS:1.0.0-beta5的
    Microsoft.AspNet.Server.WebListener:1.0.0-beta5的
    Microsoft.AspNet.StaticFiles:1.0.0-beta5的
    Microsoft.AspNet.Tooling.Razor:1.0.0-beta5的
    Microsoft.Framework.Configuration:1.0.0-beta8
    Microsoft.Framework.Configuration.Abstractions:1.0.0-beta8
    Microsoft.Framework.Configuration.Binder:1.0.0-beta8
    Microsoft.Framework.Configuration.Json:1.0.0-beta5的
    Microsoft.Framework.Configuration.UserSecrets:1.0.0-beta5的
    Microsoft.Framework.Logging:1.0.0-beta5的
    Microsoft.Framework.Logging.Console:1.0.0-beta5的
    Microsoft.VisualStudio.Web.BrowserLink.Loader:14.0.0-beta5的
  },  命令:{
    网络:Microsoft.AspNet.Hosting --config hosting.ini
    EF:EntityFramework.Commands
  },  构架: {
    dnx451:{},
    dnxcore50:{}
  },  排除:[
    wwwroot的
    node_modules
    bower_components
  ]
  publishExclude:[
    node_modules
    bower_components
    **。xproj
    **。用户,
    **。vspscc
  ]
  脚本:{
    prepublish:故宫安装,亭子安装,大口喝干净,吞掉分钟]
  },
  配置:{
  }
}


解决方案

ConfigurationBuilder appEnv.ApplicationBasePath 作为参数,而是有 SetBasePath 方法。

因此​​,改变你的code为:

  VAR建设者=新ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile(config.json)
                .AddJsonFile($配置{} env.EnvironmentName以.json,可选的:真正的);

Using VS 2015 with beta 8 of MVC, I receive the following error

"Severity   Code    Description Project File    Line
Error   CS1503  Argument 1: cannot convert from 'string' to 'Microsoft.Framework.Configuration.IConfigurationProvider'  NewInventory.DNX Core 5.0   F:\Projects\NewInventory\src\NewInventory\Startup.cs    35

from this portion of my startup.cs:

public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
        {
            // Setup configuration sources.

            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

            if (env.IsDevelopment())
            {
                // This reads the configuration keys from the secret store.
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }

When I hover over ConfigurationBuilder I can see its looking for'ConfigurationBuilder.ConfigurationBuilder(params IConfigurationProvider[] providers)'

How do I change the appEnv.ApplicationBasePath to an IConfigurationProvider array?

my project.json is:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-NewInventory-f5a8bab7-e95b-485b-97e9-9a072438b107",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.SqlServer":"7.0.0-beta5",
    "EntityFramework.Commands": "7.0.0-beta5",
    "Microsoft.AspNet.Mvc": "6.0.0-beta8",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
    "Microsoft.AspNet.Identity.EntityFramework":"3.0.0-beta8",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
    "Microsoft.Framework.Configuration": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Binder": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
    "Microsoft.Framework.Logging": "1.0.0-beta5",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta5",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "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": {
  }
}

解决方案

There is no more constructor of ConfigurationBuilder having appEnv.ApplicationBasePath as argument, but instead there is SetBasePath method.

So change your code to:

var builder = new ConfigurationBuilder()
                .SetBasePath(appEnv.ApplicationBasePath)
                .AddJsonFile("config.json")
                .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);

这篇关于ASP.Net5 Startup.cs ConfigurationBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆