VS 2015 (RC)下Entitiy Framework 升级后CodeFirst命令不能使用

前阵子闲的没事吧自己项目的Entitiy Framework 升级到6.1.3了,然后紧接着问题来了:

Join-Path : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:740 字符: 27
+     $toolsPath = Join-Path <<<<  $installPath tools
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
 
Join-Path : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 字符: 73
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path <<<<  $ToolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
 
不能对值为空的表达式调用方法。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 字符: 50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Join-Path : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:810 字符: 19
+         (Join-Path <<<<  $runner.ToolsPath EntityFramework.PowerShell.dll),
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
 
Join-Path : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:740 字符: 27
+     $toolsPath = Join-Path <<<<  $installPath tools
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
 
Join-Path : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:780 字符: 73
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path <<<<  $ToolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
 
不能对值为空的表达式调用方法。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 字符: 50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Join-Path : 无法将参数绑定到参数“Path”,因为该参数是空值。
所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:810 字符: 19
+         (Join-Path <<<<  $runner.ToolsPath EntityFramework.PowerShell.dll),
    + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
 

一大堆的乱起八糟的,开始以为是Entitiy Framework版本问题或者是VS的问题,各种乱试都没能成功。

无奈只得FQGOOGLE了最后得到的结论是:跟Entitiy Framework的版本以及VS都无关是PowerShell的版本问题,

查了下我机器上是2.0版本的

PS C:\Users\PC> $PSVersionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1

于是想法升级(我的版本选择错误,这是个4。0的版本建议升级3.0试试能够成功解决)

Windows Management Framework 4.0

下载地址

https://www.microsoft.com/zh-CN/download/details.aspx?id=40855

我系统是win7 于是下载了 Windows6.1-KB2819745-x64-MultiPkg.msu

悲剧的事这个PowerShell居然是4.0版本的升级过头了出现了新问题:

New-Object : 提供的值无效或属性是只读的。请更改该值,然后再试一次。所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:757 字符: 13
+     $info = New-Object System.AppDomainSetup -Property @{
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-Object],Exception
    + FullyQualifiedErrorId : SetValueException,Microsoft.PowerShell.Commands.NewObjectCommand
 
在此对象上找不到属性“PrivateBinPath”。请确认该属性存在并且可设置。所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:772 字符: 9
+         $info.PrivateBinPath += ';lib\net45'
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [],RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
使用“1”个参数调用“LoadFrom”时发生异常:“指定的路径或文件名太长,或者两者都太长。完全限定文件名必须少于 260 个字符,并且目录名必须少于 248 个字符。”所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\Entit
yFramework.psm1:780 字符: 5
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom((Join-Path $ToolsP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PathTooLongException
 
不能对 Null 值表达式调用方法。所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:781 字符: 5
+     $dispatcher = $utilityAssembly.CreateInstance(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [],RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
使用“8”个参数调用“CreateInstanceFrom”时发生异常:“指定的路径或文件名太长,或者两者都太长。完全限定文件名必须少于 260 个字符,并且目录名必须少于 248 个字符。”所在位置 F:\Source\WebSolution\packages\EntityFramework.6.1.3\t
ools\EntityFramework.psm1:809 字符: 5
+     $domain.CreateInstanceFrom(
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PathTooLongException
 

无奈继续求助GOOGLE吧

得到的结论很多有替换EntityFramework.psm1文件,有升级Nuget。

https://github.com/aspnet/EntityFramework/issues/1950#issuecomment-99164398

只得替换EntityFramework.psm1好些没啥效果

最终选择了升级NuGet 3.0 RC2

成功解决!

走了很多弯路,也不知道是不是最正确的解决版本,希望能给遇到同样问题的有所帮助吧。

作者:guozx 出处:http://www.cnblogs.com/Innovate/ 声明:原创文字只代表本人某一时间内的观点或结论,本人不对涉及到的任何代码担保。转载请标明出处!
原文地址:https://www.cnblogs.com/Innovate/p/4623074.html