万一其他人对此有麻烦,Microsoft将于2015年8月16日对框架的这一部分进行重大更改。您必须导入正确版本的依赖项,并切换到构建配置的新方法。
我的配置包括:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.Framework.Runtime": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.Framework.Configuration": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Json": "1.0.0-*"
},
...
}
受此问题启发,此代码可能会为您提供一些帮助:
using System;
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
using Messenger.Services;
using Microsoft.Framework.Configuration;
using Microsoft.Dnx.Runtime;
using Microsoft.AspNet.Hosting;
namespace Messenger
{
public class Startup
{
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddEnvironmentVariables();
Configuration = configurationBuilder.Build();
}
public IConfiguration Configuration { get; set; }
}
...
}
希望能帮助到你。
Microsoft.Extensions.Configuration
和Microsoft.Extensions.Configuration.Json