实体框架Import-Module:未加载指定的模块'... EntityFramework.psd1' [英] Entity Framework Import-Module : The specified module '...EntityFramework.psd1' was not loaded

查看:525
本文介绍了实体框架Import-Module:未加载指定的模块'... EntityFramework.psd1'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我决定将Entity Framework用于个人项目. 从我的Visual Studio 2013社区版本并使用NuGet,我安装了框架的最新版本(nuget版本2.8.60318.734和Entity Framework 6.1.3)

Recently I decided to use Entity Framework for a personal project. From my Visual Studio 2013 community edition and using NuGet I installed the latest version of the framework (nuget version 2.8.60318.734 and Entity Framework 6.1.3)

一切似乎都正常,我能够执行简单的CRUD操作,直到需要更新模型为止. 之后,我当然会收到错误消息:

Everything seems to work OK I was able to perform simple CRUD operations, till I needed to update my model. After it, of course I got the error message:

"Additional information: The model backing the 'MyContext' context has changed since 
the database was created. Consider using Code First Migrations to update the database 
(http://go.microsoft.com/fwlink/?LinkId=238269)."

似乎是一条适当的错误消息,我只需要启用迁移即可. 切换到Package Manager控制台,并且出现红色背景的消息

Seems an appropriate error message, I just need to Enable-Migrations. Switch to Package Manager Console and there was a message in bright red background

PM> Import-Module : The specified module 'D:\[MyProjects]\[ProfOfConcept]\EntityFrameworkInvalidFilepath\packages\EntityFramework.6.1.3\tools\EntityFramework.psd1' was not loaded because
 no valid module file was found in any module directory.
At D:\[MyProjects]\[ProfOfConcept]\EntityFrameworkInvalidFilepath\packages\EntityFramework.6.1.3\tools\init.ps1:8 char:14
+ Import-Module <<<<  (Join-Path $toolsPath EntityFramework.psd1)
    + CategoryInfo          : ResourceUnavailable: (D:\[MyProjects]...yFramework.psd1:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

嗯,出了点问题,我想框架的某些必要部分未正确安装,但让我们检查一下文件.该文件存在,内容似乎还可以.

Hmmmm something is wrong, I guess some needed part of the framework was not correctly installed, but let's check the file. The file was present, and the content seemed OK.

好的,让我们尝试重新安装它,以防万一第一次出现问题.我尝试使用NuGet卸载并重新安装.

Alright let's try to reinstall it, just in case something went wrong at the first time. Using NuGet I tried to uninstall, and reinstall.

正在检查Package Manager控制台,再次出现相同的可怕错误!

Checking Package Manager Console, again the same dreaded error!

嗯,让我们尝试从Package Manager控制台中进行卸载/重新安装.同样是同样的错误!

Hmmm, let's try to do the uninstall /reinstall from the Package Manager Console. Again the same error!

在花了更多时间尝试Google类似问题之后,我遇到了描述类似问题的人

After spending more time trying to Google similar problems I came across someone describing a similar problem Entity Framework with NuGet - Import-Module error in init.ps1 Tried that… no luck.

那到底是怎么回事?在一个尤里卡的瞬间,我想……等等,我的项目路线是什么?

So what is really going on? In a Eureka moment I thought… hold on, what was my project path?

D:\[MyProjects]\[ProofOfConcept]\….

可以吗?方括号可能是原因吗?

Could it be? Could the square brackets be the reason?

将项目复制到一个简单路径(d:\ tmp \ myProject),启动Visual Studio,输入程序包管理控制台",….没错!

Create a copy the project to a simple path (d:\tmp\myProject) start the Visual Studio, enter Package Management Console, …. no error !

Enable-Migrations
PM> Enable-Migrations
Checking if the context targets an existing database...
Detected database created with a database initializer. Scaffolded migration '201504051040353_InitialCreate' corresponding to existing database. To use an automatic migration instead, delete the Migrations folder and re-run Enable-Migrations specifying the -EnableAutomaticMigrations parameter.
Code First Migrations enabled for project EntityFrameworkInvalidFilepath.

就是这样!方括号是元凶

That's it!! The square brackets are the culprits

因此,如果您使用的是实体框架,请不要在路径中使用[] .

So the bottom line is this, if you are using Entity Framework don’t use [ ] in the path.

推荐答案

我最近遇到同样的问题,因为NuGet无法正确安装EF 6.1.3,因为未导入EntityFramework.psd1文件.通过Visual Studio卸载并重新安装EF并没有帮助.

I recently had the same issue with NuGet not installing EF 6.1.3 properly because the EntityFramework.psd1 file wasn't being imported. Uninstalling and re-installing EF through Visual Studio didn't help.

对我有用的是退出VS,导航到"[项目根目录] \ packages"并删除EntityFramework6.1.3目录.当您重新启动VS并转到程序包管理器控制台时,它将告知您缺少模块,并询问您是否要导入它们.单击重新加载"时,EF 6.1.3已正确安装在程序包"目录下.

What worked for me was to quit VS, navigate to '[Project Root Directory]\packages' and delete the EntityFramework6.1.3 directory. When you restart VS and go to the package manager console, it will let you know that there are modules missing and ask if you want to import them. When you click 'Reload' EF 6.1.3 is installed properly under the 'packages' directory.

就我而言,我使用的是2015RC,它具有与EF迁移有关的很多问题.

In my case I'm using the 2015RC, which has a lot of issues with EF migrations.

这篇关于实体框架Import-Module:未加载指定的模块'... EntityFramework.psd1'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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