在我添加了Microsoft.Extensions.Configuration.UserSecrets
包的 .NET Core 3.1 项目中,我单击了项目以管理机密,文件已在AppData
目录中创建,并且UserSecretsId
已自动添加到.csproj
文件中。因为Host.CreateDefaultBuilder
没有加载秘密我决定手动添加它们
if (hostContext.HostingEnvironment.IsDevelopment())
{
builder.AddUserSecrets(Assembly.GetExecutingAssembly());
}
})
.Build();
但后来我得到
System.InvalidOperationException
HResult=0x80131509
Message=Could not find 'UserSecretsIdAttribute' on assembly 'XXX'.
Check that the project for 'XXX' has set the 'UserSecretsId' build property.
If the 'UserSecretsId' property is already set then add a reference to the Microsoft.Extensions.Configuration.UserSecrets package.
Source=Microsoft.Extensions.Configuration.UserSecrets
我已经检查了预期描述中的建议,两个困境都得到了满足。