【问题标题】:Entity Framework error when running migrations运行迁移时出现实体框架错误
【发布时间】:2017-07-03 04:44:33
【问题描述】:

我在当前项目上运行迁移时遇到问题。

当我尝试在 Visual Studio 2015 上使用包管理器控制台添加迁移时,这一切都开始了。对模型所做的更改将不会被应用,并且迁移 Up/Down 方法是空的。

我尝试删除迁移、创建新迁移、删除数据库并从头开始。没有任何效果。

毕竟我使用

在项目中运行了一个完整的清理

主菜单 > 构建 > 批量构建 > 清理

在此之后,每次我尝试在包管理控制台上运行 EF 命令,例如:

PM> 更新数据库

我收到此错误:

找不到程序集 'D:\Repo\Tapr\src\Tapr.Api.\bin\Debug\net461\win7-x64\Tapr.Api.exe'。

我现在不习惯在我的project.json 上定位 win7-64 运行时。
我尝试这样做,但没有创建文件夹 \bin\Debug\net461\win7-x64

关于如何使 EF 在正确的 win10-x64 文件夹中搜索项目的任何想法?

非常感谢!


更新:

global.json

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003156"
  }
}

项目.json

{
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "compile": {
    }
  },
  "dependencies": {
    "IdentityServer4": "1.0.0",
    "IdentityServer4.AspNetIdentity": "1.0.0",
    "IdentityServer4.EntityFramework": "1.0.0",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
    "Microsoft.AspNetCore.Authentication.Facebook": "1.1.*",
    "Microsoft.AspNetCore.Authentication.Google": "1.1.*",
    "Microsoft.AspNetCore.Authentication.LinkedIn": "1.0.1",
    "Microsoft.AspNetCore.Authentication.MicrosoftAccount": "1.1.0",
    "Microsoft.AspNetCore.Authentication.Twitter": "1.1.*",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.*",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.*",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.*",
    "Microsoft.AspNetCore.StaticFiles": "1.1.*",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.*",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.*",
    "Microsoft.Extensions.Logging.Debug": "1.1.*",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "System.Linq": "4.0.0",
    "System.Reflection.TypeExtensions": "4.3.0"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.2.0-preview1-23339",
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.2.0-preview1-23339"
  },

  "frameworks": {
    "net461": {
      "dependencies": {
        "Tapr.Utils.Messenger.Email": "1.0.0-*",
        "Tapr.Utils.Messenger.Sms": "1.0.0-*"
      }
    }
  },

  "runtimeOptions": {
    "gcServer": true
  },

  "runtimes": {
    "win10-x64": {}
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config",
      "idsrv3test.pfx"
    ]
  },

  "scripts": {
    "postpublish": [
      "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
    ]
  },

  "configurations": {
    "Debug": {
      "buildOptions": {
        "define": [ "DEBUG", "TRACE" ],
        "emitEntryPoint": true,
        "preserveCompilationContext": true
      }
    },
    "Staging": {
      "buildOptions": {
        "define": [ "STAGING", "TRACE" ],
        "emitEntryPoint": true,
        "preserveCompilationContext": true
      }
    },
    "Release": {
      "buildOptions": {
        "define": [ "RELEASE", "TRACE" ],
        "emitEntryPoint": true,
        "preserveCompilationContext": true,
        "optimize": true,
        "platform": "x64"
      }
    }
  }

}

PM> dotnet --version 结果:

1.0.0-preview2-003156

【问题讨论】:

  • 请显示您的global.jsonproject.json 文件,dotnet --version 的输出(在控制台中运行)。
  • 嗨,德米特里,感谢您的回答。
  • 我用您提出的信息更新了问题。谢谢。
  • 您是否尝试从project.json 中完全删除runtimes?工具仍然是一个预览,错误或“不完整”的功能是可能的。如果确实需要,您可以在创建迁移后将其退回。
  • 你解决了我的朋友的问题。非常感谢。您想将其发布为答案,以便我将其标记为已接受吗?

标签: visual-studio-2015 .net-core entity-framework-core


【解决方案1】:

project.json 中完全删除runtimes 部分。您使用工具的预览版 - 可能存在错误或“不完整”功能。

如果确实需要,您可以在创建迁移后返回 runtimes。但是重新评估一下,你真的需要吗?拥有runtimes 创建自包含部署 (more info),您不需要在生产服务器上安装 .NET Core,而是必须在您的开发/构建机器上具有精确的运行时才能将所有必需的文件放入您的分发/发布中文件夹。

【讨论】:

  • 再次感谢德米特里!
猜你喜欢
  • 1970-01-01
  • 2016-11-18
  • 2021-07-01
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多