简体   繁体   English

Powershell无法在VS 2013 Package Manager控制台中找到其dll或依赖项

[英]Powershell fails to find its dll or dependency in VS 2013 Package Manager Console

I'm using VS Express 2013 .Net 4.5. 我正在使用VS Express 2013 .Net 4.5。 I'm designing in MVC5 and EF6 with MS SQLServer LocalDB in an Oracle VirtualBox Windows 7 64bit client. 我正在Oracle VirtualBox Windows 7 64位客户端中使用MS SQLServer LocalDB在MVC5和EF6中进行设计。

I am trying to apply SQL Server LocalDb migrations with the command: 我正在尝试通过以下命令应用SQL Server LocalDb迁移:

PM> Enable-Migrations -ContextTypeName SGHWA_MVC.Models.Context PM> Enable-Migrations -ContextTypeName SGHWA_MVC.Models.Context

This always fails. 这总是失败。

My limited web knowledge is with Web Forms so I am completely new to MVC and EF. 我对Web表单的了解很少,因此我对MVC和EF完全陌生。 Also I have never used PMC and Powershell. 我也从未使用过PMC和Powershell。 I have searched for solutions but have not found questions similar to this error that Package Manager Console produces. 我已经搜索了解决方案,但没有找到与Package Manager Console产生的此错误类似的问题。

First there is a warning:- 首先有一个警告:

Cannot determine a valid start-up project. 无法确定有效的启动项目。 Using project 'SGHWA_MVC' instead. 改用项目“ SGHWA_MVC”。 Your configuration file and working directory may not be set as expected. 您的配置文件和工作目录可能未按预期设置。 Use the -StartUpProjectName parameter to set one explicitly. 使用-StartUpProjectName参数可以显式设置一个。 Use the -Verbose switch for more information. 使用-Verbose开关以获取更多信息。

PCM drop-down box shows the Default project correctly as SGHWA_MVC. PCM下拉框正确显示默认项目为SGHWA_MVC。 The solution property pages show this one project as the start-up project. 解决方案属性页面将这个项目显示为启动项目。

I went to http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference but could not see the -StartUpProjectName parameter mentioned. 我去了http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference,但是看不到提到的-StartUpProjectName参数。 I'm not sure to which command this parameter applies. 我不确定此参数适用于哪个命令。

Then the first error appears:- 然后出现第一个错误:

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file://\\W7O2007\\Users\\Admin\\Documents\\Visual Studio 2013\\Projects\\SGHWA_MVC\\packages\\EntityFramework.6.1.0\\tools\\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"At \\W7O2007\\Users\\Admin\\Documents\\Visual Studio 2013\\Projects\\SGHWA_MVC\\packages\\EntityFramework.6.1.0\\tools\\EntityFramework.psm1:780 char:62 带有“ 1”参数的调用“ LoadFrom”的异常:“无法加载文件或程序集'file:// \\ W7O2007 \\ Users \\ Admin \\ Documents \\ Visual Studio 2013 \\ Projects \\ SGHWA_MVC \\ packages \\ EntityFramework.6.1.0 \\ tools \\ EntityFramework.PowerShell.Utility.dll'或其依赖项之一。不支持操作。(HRESULT的异常:0x80131515)“在\\ W7O2007 \\ Users \\ Admin \\ Documents \\ Visual Studio 2013 \\ Projects \\ SGHWA_MVC \\ packages \\ EntityFramework.6.1.0 \\ tools \\ EntityFramework.psm1:780 char:62
+ $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $ToolsPath EntityFramework.PowerShell.Utility.dll)) + $ utilityAssembly = [System.Reflection.Assembly] :: LoadFrom <<<<(((加入路径$ ToolsPath EntityFramework.PowerShell.Utility.dll))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException + CategoryInfo:未指定:(:) [],MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException + FullyQualifiedErrorId:DotNetMethodException

It suggests the file is not there to be loaded but it does exist on the PC at the path shown. 这表明该文件不存在要加载的位置,但确实存在于PC上,如图所示。 I suspect it is the Join-Path that fails but am unsure how to test this. 我怀疑是Join-Path失败了,但是不确定如何测试。

The packages.config files has a line:- packages.config文件中有一行:-

(leading < removed) package id="Powershell.Deployment" version="1.1.0.0" targetFramework="net45" /> (导致<删除)程序包id =“ Powershell.Deployment” version =“ 1.1.0.0” targetFramework =“ net45” />

My research shows it could be permissions, remote access, that the Project Build should have Generate Serialization Assembly as 'On', 'Off' or 'Auto' or even NuGet packages that cause this but I cannot determine if it is a PMC, NuGet, Powershell or Windows problem. 我的研究表明,项目构建应该将“生成序列化程序集”设置为“打开”,“关闭”或“自动”,甚至是导致此问题的NuGet程序包,也可能是权限,远程访问,但我无法确定它是否是PMC,NuGet ,Powershell或Windows问题。

Two more error messages appear relating to similar problems in EntityFramework.psm1 and seem to be related to this first problem. 出现另外两个错误消息,它们与EntityFramework.psm1中的类似问题有关,并且似乎与第一个问题有关。

Please can anyone advise the likely cause and guide me through what/how to test and solve this? 请任何人提供建议可能的原因并指导我通过什么/方法进行测试和解决吗?

I realize this is an old thread, but I just ran into this problem using a newly-installed copy of Microsoft Visual Studio 2015 Enterprise with Update 1. 我意识到这是一个旧线程,但是我只是使用带有Update 1的新安装的Microsoft Visual Studio 2015 Enterprise副本遇到了此问题。

My solution was to delete this folder: 我的解决方案是删除此文件夹:

C:\Users\\(my user ID)\\.nuget\packages\EntityFramework\6.1.3

and allow it to be regenerated the next time the Entity Framework is added to a project. 并允许在下一次将实体框架添加到项目中时重新生成它。 Originally, the PowerShell DLL's were missing from this folder. 最初,此文件夹中缺少PowerShell DLL。 Strange. 奇怪。

Your question has several parts. 您的问题分为几个部分。

First, you cannot find the documentation, and you have it at your fingertips: 首先,您找不到文档,并且唾手可得:

Update-Database -?

Then, you can read at the bottom of this help: 然后,您可以阅读此帮助的底部:

TO see the examples, type: "get-help Update-Database -examples".
For more information, type: "get-help Update-Database -detailed".
For technical information, type: "get-help Update-Database -full".

Second, -StartupProjectName is required to find the configuration file that has the required connection string (you also specify the connection directly using another options) NOTE: This has nothing to do with the solution's startup project 其次,需要-StartupProjectName来查找具有所需连接字符串的配置文件(您也可以直接使用其他选项指定连接) 注:这与解决方案的启动项目无关

And, if having this clear doesn't solve the problem, try uninstalling and reinstalling the EntityFramework package (in case something went wrong). 并且,如果清除此内容仍不能解决问题,请尝试卸载并重新安装EntityFramework软件包(以防万一出现问题)。 Take into account that, if you have several projects, it's possible that you need to do this for all the affected projects. 请考虑到,如果您有多个项目,则可能需要对所有受影响的项目执行此操作。 You can do this more easily using the Manage Nuget Packages for Solution... menu option. 您可以使用“ Manage Nuget Packages for Solution...菜单选项更轻松地执行此操作。

Edit 编辑

(Added to help choose the right Default project in Package Manager Console or specify -ProjectName ). (已添加以帮助在Package Manager控制台中选择正确的Default项目或指定-ProjectName )。

I forgot to answer the most important part of the question: for Migrations commands to work, it's necessary to run them on a project that references the EF assemblies. 我忘了回答问题中最重要的部分:为了使Migrations命令起作用,有必要在引用EF程序集的项目上运行它们。 This solves the missing assembly problem. 这样可以解决缺少的装配问题。

In this case it's clear that the chosen StartUpProject, which is the Web App have the connection strings, but doesn't have a reference to EF. 在这种情况下,很明显,所选的StartUpProject(即Web应用程序)具有连接字符串,但没有对EF的引用。 That's why running the command fails. 这就是运行命令失败的原因。 And most probably the command is being run with this as the default project in the console. 并且很可能该命令将作为默认项目在控制台中运行。

To solve this, you need to run Migrations within a project which has references to EF, and it will work flawlessly: choose that project in the drop down list named "Default project" on the top bar of the Package Manager Console. 要解决此问题,您需要在一个引用了EF的项目中运行Migrations,它可以正常运行:在Package Manager控制台顶部的名为“默认项目”的下拉列表中选择该项目。

This can also be done by specifying the -ProjectName option, which must point to the project containing the Migration configuration class, and thus, have also the reference to EF. 也可以通过指定-ProjectName选项来完成,该选项必须指向包含Migration配置类的项目,因此也要引用EF。 NOTE: you must also sepcify the -ConfigurationTypeName param if you have several migrations for several contexts, as supported from EF 6 . 注意:您还必须sepcify的-ConfigurationTypeName PARAM,如果你有好几个环境迁移,从EF 6支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM