asp.net-core - 在程序集 'UserSecretsIdAttribute' 上找不到 'ef'

标签 asp.net-core

我使用的是 ASP.NET Core 1.1,启动时出现以下内容:

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddUserSecrets();

我使用 csproj 文件而不是我添加的 JSON:

<PropertyGroup>
   <UserSecretsId>8844d677-223b-4527-a648-387a65933d55</UserSecretsId>
</PropertyGroup>

但是当我运行命令时:

dotnet ef migrations add "InitialCommit"

我收到错误:

An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Could not find 'UserSecretsIdAttribute' on assembly 'ef, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"

知道为什么吗?

最佳答案

您遇到了此问题:https://github.com/aspnet/Configuration/issues/543

解决方案是将您的调用 .AddUserSecrets() 更改为 .AddUserSecrets(Assembly assembly)

请参阅此公告,了解弃用 project.json 如何需要对用户 secret 进行重大更改:https://github.com/aspnet/Announcements/issues/209

关于asp.net-core - 在程序集 'UserSecretsIdAttribute' 上找不到 'ef',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40770111/

相关文章:

docker - 在文件 '.\docker-compose.yml'中,服务 'version'必须是映射而不是字符串

amazon-web-services - 使用 amazon cognito 的电子邮件验证链接

c# - 共享类与 swagger 生成的类

.NET Core 指定的框架 'Microsoft.NETCore.App' ,版本 '1.1.2' 未找到

c# - 添加查询字符串参数重定向至 IdP

C# 可选枚举类型属性 setter 在经典 .net 中编译但不在 .net 核心中编译? (cs0019)

c# - 在 .NET Core 中以字符串形式返回 View

asp.net-core - 在现有的 AspNetUser 表中手动创建列是个好主意吗?

c# - 核心 3.1 - 绑定(bind) Body 中的一些属性和 Header 中的其他一些属性

visual-studio - .Net Core 1.1.0 NuGet程序包无法在Visual Studio Mac中安装