【问题标题】:Could not find 'UserSecretsIdAttribute' on assembly 'ef'在程序集“ef”上找不到“UserSecretsIdAttribute”
【发布时间】:2016-11-23 16:52:02
【问题描述】:

我正在使用 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"

知道为什么吗?

【问题讨论】:

    标签: asp.net-core


    【解决方案1】:

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

    解决办法是将你的电话.AddUserSecrets()改为.AddUserSecrets(Assembly assembly)

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

    【讨论】:

    • 如果您收到错误 'ConfigurationBuilder' does not contain a definition for 'AddUserSecrets',请确保添加此缺失的 Nuget 包:Microsoft.Extensions.Configuration.UserSecrets
    【解决方案2】:

    我也有这个问题。我的解决方案是安装nuget包Microsoft.Extensions.Configuration.UserSecrets

    【讨论】:

      【解决方案3】:

      当我更改 .csproj 中的包版本时,它终于对我有用了:

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

      到:

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

      【讨论】:

        猜你喜欢
        • 2017-04-03
        • 1970-01-01
        • 2013-05-06
        • 2023-03-24
        • 2010-10-19
        • 2012-10-13
        • 2011-09-23
        • 2019-06-06
        相关资源
        最近更新 更多