在Visual Studio

时间:2017-10-12 06:49:42

标签: asp.net-core-webapi asp.net-core-2.0

我的UserSecrets在我的.NET 2.0 Core Web API上正常运行。我还使用基于下面函数的测试服务器对所有集成测试套件使用测试服务器正常工作(所有测试都通过)。当我使用新的实时测试功能时会出现问题。我已经在使用之前记录的新扩展方法来处理这种类型的bug,所以我不确定还有什么要改变的。如果我将设置移回常规appsetting.json并删除AddUserSecrets调用,则实时测试按预期工作(但显然我不想这样做)。

    public static TestServer CreateServer()
    {
        var server = new TestServer(new WebHostBuilder()
            .ConfigureAppConfiguration(config => config.AddUserSecrets<Startup>())
            .ConfigureServices((context, services) => services.AddOptions()
            .Configure<AppSettings>(context.Configuration.GetSection("AppSettings")))
            .UseStartup<Startup>());
        return server;
    }

消息:

  

System.InvalidOperationException:找不到   程序集“RouteManager.Core.Server”上的“UserSecretsIdAttribute”。校验   'RouteManager.Core.Server'的项目设置了   'UserSecretsId'构建属性。如果'UserSecretsId'属性是   已经设置然后添加一个引用   Microsoft.Extensions.Configuration.UserSecrets包。

0 个答案:

没有答案