powershell - PowerShell 中的 EF6 添加迁移,在 Visual Studio 之外
问题描述
如何Add-Migration
在 PowerShell 窗口中在 Visual Studio 之外运行 EF6?
当我尝试运行它时,出现以下错误消息:
Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
解决方案
您需要确保模块已加载。因为这是来自该控制台窗口的 VS 环境的一部分,所以默认情况下它会加载一些不同的模块。您可以通过在 VS 中打开控制台来解决此问题,然后使用
PS ~/> $path = (Get-Module -Name EntityFrameworkCore).Path
对我来说,这解决了:
PS ~/> $path
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.1.1\tools\EntityFrameworkCore.psm1
因此,您可以采用该路径并将其导入常规的 powershell 窗口:
PS ~/> Import-Module -Name $path
但是在查看文件夹(令人讨厌地不符合标准)之后,它还有一个模块清单文件(.psd1
),这是您应该导入的:
PS ~/> Set-Location -Path 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.1.1\tools'
PS /Program Files/dotnet/sdk/NuGetFallbackFolder/microsoft.entityframeworkcore.tools/2.1.1/tools/> Import-Module -Name EntityFrameworkCore.psd1
脚注:这是我的 VS 安装初始化其控制台的方式:
Import-Module 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\NUGET\Modules\NuGet\NuGet.psd1'
$__pc_args=@(); $input|%{$__pc_args+=$_}; & 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.1.1\tools\init.ps1' $__pc_args[0] $__pc_args[1] $__pc_args[2]; Remove-Variable __pc_args -Scope 0
推荐阅读
- c# - 为什么 IsLiteral 对小数返回 false?
- android - 未编译的 PNG 文件作为参数传递。必须先编译成 .flat 文件
- asp.net-core - ASP.NET Core 2.1 对完整 .NET 框架的性能改进?
- python - python sqlite3出现错误:sqlite3.OperationalError:数据库被锁定
- apache-camel - Camel-Hystrix-EIP :是否可以根据内容主体动态选择 onFallback 或 onFallbackViaNetwork 作为交换?
- android - memset 导致挂在特定设备中
- asp.net-web-api - 无法使用 ReadAsAsync 获取对象
- javascript - 如何在鼠标悬停时播放音频?
- laravel - VueJs 不适用于 Laravel 5.6
- iphone - 使用 AVFoundation 在 Iphone 照片捕获中图像捕获比闪存慢