我正在try 为我正在构建的.Net Web应用程序设置应用程序基本路径.我在配置生成器上不断收到错误.这就是我得到的错误.

DNX,Version=v4.5.1 error CS1061: 'ConfigurationBuilder' does not contain a definition for 'SetBasePath' and no extension method 'SetBasePath' accepting a first argument of type 'ConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)

我假设我的.AddJsonFile().AddEnvironmentVariables()也会有同样的错误.我做错什么了吗?我没有为我的项目添加正确的依赖项.json?我已经附上了我的创业公司.cs和我的项目.json.

project.json

{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"tooling": {
"defaultNamespace": "TripPlanner"
},

"dependencies": {
  "Microsoft.AspNet.StaticFiles":  "1.0.0-rc1-final",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
  "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
  "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
  "Microsoft.Framework.Configuration": "1.0.0-beta8",
  "Microsoft.Framework.DependencyInjection": "1.0.0-beta8"
  //"Microsoft.Extensions.PlatformAbstractions": "1.0.0-beta8"
},

"commands": {
  "web": "Microsoft.AspNet.Server.Kestrel"
},

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

"exclude": [
  "wwwroot",
  "node_modules"
],
"publishExclude": [
  "**.user",
  "**.vspscc"
 ]
}

创业.反恐精英

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using TripPlanner.Services;



namespace TripPlanner
{
  public class Startup
  {
    public static IConfigurationRoot Configuration;

    public Startup(IApplicationEnvironment appEnv){
        var builder = new ConfigurationBuilder()
            .SetBasePath(appEnv.ApplicationBasePath)
            .AddJsonFile("config.json")
            .AddEnvironmentVariables();

        Configuration = builder.Build();
    }

    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
    {
        services.AddMvc();
        #if DEBUG
        services.AddScoped<IMailService, DebugMailService> ();
        #else
        services.AddScoped<IMailService, RealMailService> ();
        #endif
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
       //app.UseDefaultFiles();
       app.UseStaticFiles();
       app.UseMvc(config =>
       {
           config.MapRoute(
               name: "Default",
               template: "{controller}/{action}/{id?}",
               defaults: new { controller  = "App", action = "Index"}
           );
       });

    }

    // Entry point for the application.
    public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run<Startup>(args);
  }
}

The error is in the public startup function right near the top of 创业.反恐精英.

推荐答案

我能够解决这个问题.如果尚未解决,请try 以下方法

"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final"

而且它应该能行得通

Asp.net相关问答推荐

从组件属性调用异步方法的正确方法

什么是 SNIReadSyncOverAsync,为什么需要很长时间才能完成?

在每个对象上设置 ClientIDMode = Static 是否有任何缺点(在母版页的 maincontent 上设置)

Web 部署工具 2.1 和 Web 部署 3.5 有什么区别?从 VS 2010 部署需要哪一个?

如何在asp.net中单击按钮的新选项卡中打开页面?

SignalR 不在服务器上使用 Session

使用实体框架从存储过程中获取数据

在构建时自动停止/重新启动 ASP.NET 开发服务器

防止在 Visual Studio 2008 ASP.NET Web 窗体中复制粘贴时自动生成 ID

您如何以编程方式填写表格并发布网页?

ASP.NET 中的 <%# Bind("") %> 和 <%# Eval("") %> 有什么区别?

Cache.Add 绝对过期 - 是否基于 UTC?

如何使用 encodeURIComponent() 解码在 JS 中编码的 HTML?

将字典绑定到中继器

在 Asp.Net Core 中动态更改连接字符串

ASP.NET 核心,更改未经授权的默认重定向

判断 IQueryable 结果集的最佳方法是什么?

在控制器 asp.net-core 中获取当前区域性

ASP.NET 网格视图与列表视图

如何在asp.net的GridView中按列名而不是按索引获取单元格值