2016-05-12 128 views
1

我試圖建立從CLI使用dotnet build我的.NET的核心應用程序,但每一次我得到這個錯誤:構建失敗.NET的核心應用由於缺少定義

'IConfigurationBuilder' does not contain a definition for 'AddEnvironmentVariables' and no extension method 'AddEnvironmentVariables' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)

這是我的ConfigureServices方法Startup.cs那裏的問題正在發生的事情:

public void ConfigureServices(IServiceCollection services) 
    { 
     var builder = new ConfigurationBuilder() 
      .AddJsonFile("config.json") 
      .AddEnvironmentVariables() 
      .Build(); 

     services.AddEntityFrameworkSqlServer() 
      .AddDbContext<MyContext>(options => 
       options.UseSqlServer(builder["Data:MyContext:ConnectionString"])); 

     services.AddIdentity<ApplicationUser, ApplicationRole>() 
      .AddEntityFrameworkStores<MyContext>() 
      .AddDefaultTokenProviders() 
      .AddOpenIddictCore<Application>(config => config.UseEntityFramework()); 

     services.AddMvc(); 

     services.AddScoped<OpenIddictManager<ApplicationUser, Application>, CustomOpenIddictManager>(); 
    } 

看着this example我什麼也看不到明顯的錯誤與我Startup.cs

更新project.json文件:

{ 
    "compilationOptions": { 
    "debugType": "portable", 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "dependencies": { 
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha1-*", 
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.Hosting": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-*", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-*", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-*", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-*", 
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-*", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-*", 
    "OpenIddict.Core": "1.0.0-*", 
    "OpenIddict.EF": "1.0.0-*" 
    }, 

    "frameworks": { 
    "net451": { 
     "frameworkAssemblies": { 
     "System.ComponentModel": { "type": "build" } 
     } 
    }, 

    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.0-rc2-*" 
     } 
     }, 

     "imports": [ 
     "dnxcore50", 
     "portable-net451+win8" 
     ] 
    } 
    }, 

    "tools": { 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": { 
     "version": "1.0.0-rc2-*", 
     "imports": "portable-net45+wp80+win8+wpa81+dnxcore50" 
    } 
    }, 

    "scripts": { 
    "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" 
    }, 

    "content": [ 
    "wwwroot", 
    "Views", 
    "config.json", 
    "web.config" 
    ], 

    "exclude": [ 
    "wwwroot", 
    "node_modules" 
    ], 

    "publishExclude": [ 
    "**.user", 
    "**.vspscc" 
    ] 
} 

回答

2

您需要Microsoft.Extensions.Configuration命名空間範圍,以獲取擴展方法。要麼完全限定它,或添加到您的文件的頂部:

using Microsoft.Extensions.Configuration; 

您還需要參考的NuGet Microsoft.Extensions.Configuration.EnvironmentVariables

+0

謝謝,它正在建設中。我認爲這個軟件包已經重新命名了,所以我沒有看到它。核心軟件包總是在不斷變化。 –

+1

@ barnacle.m請記住,源代碼位於GitHub上,所以如果您有任何疑問,可以隨時查看。 – mason

1

要添加的正確包。 AddEnvironmentVariables()Microsoft.Extensions.Configuration.EnvironmentVariables

相關問題