ef-core 添加迁移不起作用
ef-core Add-Migration not working
刚开始学习.net core 2.0
当我尝试创建迁移时:
PM> Add-Migration InitialModel
我得到错误:
Add-Migration : Exception calling "Substring" with "1" argument(s):
"StartIndex cannot be less than zero. Parameter name: startIndex" At
line:1 char:1
+ Add-Migration InitialModel
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration
我的 dotnet --info
.NET Command Line Tools (2.0.0)
Product Information: Version: 2.0.0 Commit SHA-1 hash:
cdcd1928c9
Runtime Environment: OS Name: Windows OS Version: 10.0.15063
OS Platform: Windows RID: win10-x64 Base Path: C:\Program
Files\dotnet\sdk.0.0\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0 Build :
e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
我的 csproj 文件:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
感谢帮助!
如果在 Visual Studio 中加载 v1.x 版本的 PMC(程序包管理器控制台)迁移命令,然后您尝试 运行 针对的命令,我会看到此错误发生v2.x 申请。例如。如果您创建或打开一个 ASP.NET Core 1.1 应用程序,然后在同一个 Visual Studio 会话中创建一个 ASP.NET Core 2.0 应用程序。
这种情况的解决方法是在使用 2.0 应用程序之前重新启动 Visual Studio。
根据 bricelam,NuGet 中有一种机制应该会导致将较新版本的 PMC 命令加载到 Visual Studio,但不幸的是,该机制并未在所有情况下都被触发。
刚开始学习.net core 2.0
当我尝试创建迁移时:
PM> Add-Migration InitialModel
我得到错误:
Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. Parameter name: startIndex" At line:1 char:1 + Add-Migration InitialModel + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration
我的 dotnet --info
.NET Command Line Tools (2.0.0)
Product Information: Version: 2.0.0 Commit SHA-1 hash: cdcd1928c9
Runtime Environment: OS Name: Windows OS Version: 10.0.15063 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk.0.0\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
我的 csproj 文件:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
感谢帮助!
如果在 Visual Studio 中加载 v1.x 版本的 PMC(程序包管理器控制台)迁移命令,然后您尝试 运行 针对的命令,我会看到此错误发生v2.x 申请。例如。如果您创建或打开一个 ASP.NET Core 1.1 应用程序,然后在同一个 Visual Studio 会话中创建一个 ASP.NET Core 2.0 应用程序。
这种情况的解决方法是在使用 2.0 应用程序之前重新启动 Visual Studio。
根据 bricelam,NuGet 中有一种机制应该会导致将较新版本的 PMC 命令加载到 Visual Studio,但不幸的是,该机制并未在所有情况下都被触发。