为什么Visual Studio告诉我我需要引用System.Private.CoreLib? [英] Why is Visual Studio telling me I need to reference System.Private.CoreLib?

查看:1377
本文介绍了为什么Visual Studio告诉我我需要引用System.Private.CoreLib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试使用EF Core,并编写了一个非常简单的MVC应用程序以使自己的脚步变得湿润.我正在使用一种方法来播种在 UnicornStore项目他们在Startup.cs中编写一些代码来迁移数据库,然后运行种子方法.

I'm trying out EF Core for the first time and have coded a very simple MVC app to get my feet wet. I am using a method for seeding the database found in the UnicornStore project where they write some code in Startup.cs to migrate the database and then run a seed method.

在调用种子方法之前,他们运行此DbContext扩展方法来检查是否已应用所有迁移:

Before they call the seed method, they run this DbContext extension method to check if all migrations have been applied:

using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

namespace UnicornStore.Models
{
    public static class DbContextExtensions
    {
        public static bool AllMigrationsApplied(this DbContext context)
        {
            var applied = context.GetService<IHistoryRepository>()
                .GetAppliedMigrations()
                .Select(m => m.MigrationId);

            var total = context.GetService<IMigrationsAssembly>()
                .Migrations
                .Select(m => m.Key);

            return !total.Except(applied).Any();
        }
    }
}

我已经在我的应用程序中使用了相同的方法,并且一切正常-代码将编译,数据库将被迁移并植入种子.但是,Visual Studio(2017企业版)用红色强调了这一行:

I've put this same method in my application and everything works -- the code compiles and the database is migrated and seeded. However, Visual Studio (2017 Enterprise) is red underlining this line:

context.GetService<IMigrationsAssembly>()
                    .Migrations
                    .Select(m => m.Key);

如果我将鼠标悬停在红线上,它会告诉我:

If I hover over the red line, it tells me:

模块'System.Private.CoreLib,版本= 4.0.0.0,区域性=中性, 应该引用PublicKeyToken = foo'

Module 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=foo' should be referenced

谁能告诉我为什么我收到此消息?我实际上试图添加对System.Private.CoreLib的引用以查看会发生什么,并且导致了很多错误(未定义的System.Object等).我永远不愿意留下这样无法解决的问题,以防它们以后再咬我,所以任何解决方案(或确认我可以保留此消息并忽略消息)都将不胜感激!

Can anyone tell me why I am getting this message? I actually tried to add a reference to System.Private.CoreLib to see what would happen, and that caused a ton of errors (undefined System.Object, etc). I'm never comfortable leaving things like this unresolved in case they come back to bite me later, so any resolution (or a confirmation that I can leave this be and ignore the message) would be appreciated!

推荐答案

是否已安装R#?您可能已经遇到了这个问题: RSRP-464676

Do you have R# installed? You might have been hitting this issue: RSRP-464676

如果是这样,请尝试暂停R#并查看问题是否不再显示.

If so, try suspending R# and see if the issues are not shown anymore.

这篇关于为什么Visual Studio告诉我我需要引用System.Private.CoreLib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆