Asp.net mvc 5 UserSecrets.dll找不到project.json
我正在将一个aspnet5/rc-1网站转换为发布的aspnet核心。我在开发环境中遇到了一个涉及用户机密的问题 在启动构造函数中调用AddUserSecrets会引发异常:Asp.net mvc 5 UserSecrets.dll找不到project.json,asp.net-mvc-5,asp.net-core,asp.net-core-mvc,Asp.net Mvc 5,Asp.net Core,Asp.net Core Mvc,我正在将一个aspnet5/rc-1网站转换为发布的aspnet核心。我在开发环境中遇到了一个涉及用户机密的问题 在启动构造函数中调用AddUserSecrets会引发异常: public Startup( IHostingEnvironment env ) { // Set up configuration sources. var builder = new ConfigurationBuilder() .AddJsonFile( "appsettings.j
public Startup( IHostingEnvironment env )
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile( "appsettings.json" )
.AddJsonFile( $"appsettings.{env.EnvironmentName}.json", optional: true );
if( env.IsDevelopment() )
{
// this line blows up
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
错误消息的大意是在bin/Debug/netcoreapp1.0文件夹中找不到project.json文件……这很奇怪,因为我本来不希望在可分发可执行文件文件夹中找到project.json文件
这一切在rc1下都很好,所以有些东西已经改变了
其他信息
以下是异常详细信息:
System.InvalidOperationException未由用户代码处理HResult=-2146233079 Message=无法在中找到project.json “C:\Programming\SpeedView\src\SpeedView\bin\Debug\netcoreapp1.0\”。
Source=Microsoft.Extensions.Configuration.UserSecrets堆栈跟踪: 位于Microsoft.Extensions.Configuration.UserSecrets.PathHelper.GetSecretsPath(IFileProvider 供应商) 位于Microsoft.Extensions.Configuration.ConfigurationExtensions.AddUserSecrets(IConfigurationBuilder 配置) 在C:\Programming\SpeedView\src\SpeedView\Startup.cs中的SpeedView.Startup..ctor(IHostingEnvironment env)处:第48行
内部异常: 下面是project.json文件:
{
"userSecretsId": "aspnet5-SpeedView-f526a1b2-f58b-4e04-b189-8442609eff8c",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Antiforgery": "1.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": {
"version": "1.0.0",
"type": "build"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"AutoMapper": "5.0.2",
"Serilog.Extensions.Logging": "1.1.0",
"Serilog.Sinks.ColoredConsole": "2.0.0",
"Serilog.Sinks.Literate": "2.0.0",
"Serilog.Sinks.RollingFile": "2.2.0",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp siteprep" ]
}
}
不要忘记设置基本路径:
public Startup( IHostingEnvironment env )
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath) // Add this line <-----
.AddJsonFile( "appsettings.json" )
.AddJsonFile( $"appsettings.{env.EnvironmentName}.json", optional: true );
公共启动(IHostingEnvironment环境)
{
//设置配置源。
var builder=new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)//添加此行不要忘记设置基本路径:
public Startup( IHostingEnvironment env )
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath) // Add this line <-----
.AddJsonFile( "appsettings.json" )
.AddJsonFile( $"appsettings.{env.EnvironmentName}.json", optional: true );
公共启动(IHostingEnvironment环境)
{
//设置配置源。
var builder=new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)//添加这一行。您可以发布实际的异常消息和您的project.json文件吗?您可以发布实际的异常消息和您的project.json文件吗?Thanx,Gerardo;这就是问题所在。您知道这一更改背后的原因在哪里吗?在这里,他们决定创建BasePath,在这里,他们将其从Con中删除figurationBuilder构造函数欣赏链接。现在我了解了更改,以支持解耦。Thanx,Gerardo;这就是问题所在。你知道这一更改背后的原因在哪里吗?在这里,他们决定创建BasePath,在这里,他们将其从ConfigurationBuilder构造函数中删除。欣赏链接。现在我明白了d)改变,以支持解耦。