VS2015 ASP.NET 5空项目无法正常工作,找不到ConfigurationBuilder.Build [英] VS2015 ASP.NET 5 Empty project doesn't work, can't find ConfigurationBuilder.Build

查看:66
本文介绍了VS2015 ASP.NET 5空项目无法正常工作,找不到ConfigurationBuilder.Build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试新的VS2015项目.我正在关注本教程,但是缺少它某物.当我运行它时,出现500错误:

Trying out the new VS2015 projects. I was following this tutorial but it's missing something. When I run it I get a 500 error:

System.MissingMethodException: Method not found: 'Microsoft.Framework.Configuration.IConfiguration Microsoft.Framework.Configuration.ConfigurationBuilder.Build()'.
at Microsoft.AspNet.Loader.IIS.RuntimeHttpApplication.ApplicationStart(IHttpApplication application)
at Microsoft.AspNet.Loader.IIS.HttpApplicationBase.InvokeApplicationStart(IHttpApplication application)

.NET Framework version 4.0.30319.42000   |   Microsoft.AspNet.Loader.IIS version 1.0.0-beta5-11951   |   IIS version 10.0.10117.0 (fbl_srv2_iis_dev(sujitn).150512-1839)   |   Need help?

经过一番阅读,我发现您需要一个Configuration实例,尽管我发现的示例对我不起作用.他们都将实例设置为配置"字段,但是似乎不存在.这些配置行全为红色,因为名称不存在:

After some reading I discovered that you need a Configuration instance, though the examples I found don't work for me. They all set the instance to a Configuration field but that doesn't seem to exist. These Configuration lines are all red because the name doesn't exist:

public class Startup
{
    public Startup() {
        Configuration = new ConfigurationBuilder();
    }

    public void ConfigureServices(IServiceCollection services)
    {
        Configuration = new ConfigurationBuilder();
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app)
    {
        Configuration = new ConfigurationBuilder();

        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello World!");
        });

        app.UseMvc(m => {
            m.MapRoute(
                name: "default",
                template: "{controller}/{action}/{id?}",
                defaults: new { controller = "Home", action = "Index" });
        });
    }
}

这是使用空项目中的默认Startup类.我手动添加了gulp和angular节点模块.我一定想念一些东西,但我不知道是什么...

This is using the default Startup class from the empty project. I added the gulp and angular Node modules manually. I must be missing something but I have no idea what...

更新:这些是我在Startup.cs中的用法:

Update: These are my usings in Startup.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Configuration;

更新:这是我当前的 project.json 文件(我尚未手动修改):

Update: This is my current project.json file (I haven't modified this manually yet):

{
    "webroot": "public",
    "version": "1.0.0-*",

    "dependencies": {
        "Microsoft.AspNet.Mvc": "6.0.0-beta7",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5"
    },

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

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

  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "exclude": [
    "public",
    "node_modules",
    "bower_components"
  ]
}

更新:根据注释将 beta5 s更改为 beta7 s后,我跳过了此 ConfigurationBuilder 错误,然后转到无法加载文件或程序集'Microsoft.Dnx.Host.Clr'或其依赖项之一"错误,我怀疑这是另一个版本问题,我现在正在调查...但是我想应该是一个不同的问题.

Update: After changing the beta5s to beta7s, based on comments, I got past this ConfigurationBuilder error and moved on to a "Could not load file or assembly 'Microsoft.Dnx.Host.Clr' or one of its dependencies" error, which I suspect is another version issue and I'm looking into now...but that would be a different question I suppose.

推荐答案

如Henk Mollema的评论中所述,未找到 ConfigurationBuilder.Build 的原因,而我的 Configuration 行是红色的是我混合了软件包版本(有些beta5和一些beta7).此功能或者是在beta5之后的版本中添加的,或者由于库不匹配而找不到.在 project.json 中升级到beta7可以解决该问题.

As noted in comments by Henk Mollema, the reason ConfigurationBuilder.Build was not found and my Configuration lines were red is that I had mixed package versions (some beta5 and some beta7). This functionality was either added in a version later than beta5, or it couldn't be found due to the mismatched libraries. Upgrading to beta7 in project.json fixed it.

我提到的后续错误也是也已修复.

The subsequent error I mentioned was fixed as well.

这篇关于VS2015 ASP.NET 5空项目无法正常工作,找不到ConfigurationBuilder.Build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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