找不到' UserSecretsIdAttribute'关于组装' ef'

时间:2016-11-23 16:52:03

标签: 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"

知道为什么吗?

3 个答案:

答案 0 :(得分:7)

您遇到过这个问题:https://github.com/aspnet/Configuration/issues/543

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

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

答案 1 :(得分:0)

当我在.csproj中更改了一个包的版本时,它终于为我工作了:

<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />

为:

<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />

答案 2 :(得分:0)

我也遇到了这个问题。我的解决方案是安装nuget软件包Microsoft.Extensions.Configuration.UserSecrets