通过VSTS进行.NET Core EF迁移

时间:2018-06-04 00:46:38

标签: .net entity-framework .net-core azure-devops

当我尝试在我的机器上本地构建迁移脚本时,它可以正常工作。但是,在VSTS Build中,我得到一个奇怪的例外:

**Exception message:**
The migration 'ΓÇôp' was not found.

**Verbose Log:**
dotnet exec --depsfile D:\a\1\s\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.deps.json --additionalprobingpath C:\Users\VssAdministrator\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft SDKs\NuGetPackagesFallback" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\a\1\s\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.runtimeconfig.json "C:\Program Files\dotnet\sdk\2.1.300-rc1-008673\DotnetTools\dotnet-ef\2.1.0-rc1-final\tools\netcoreapp2.0\any\tools\netcoreapp2.0\any\ef.dll" migrations script -p ..\Company.BaseClassLibrary\Company.BaseClassLibrary.csproj -o D:\a\1\a\Migrations\migration.sql -i --assembly D:\a\1\s\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.dll --startup-assembly D:\a\1\s\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.dll --project-dir D:\a\1\s\Company.API.Auth\ --language C# --working-dir D:\a\1\s\Company.API.Auth --verbose --root-namespace Company.A...
Using assembly 'Company.API.Auth'.
Using startup assembly 'Company.API.Auth'.
Using application base 'D:\a\1\s\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0'.
Using working directory 'D:\a\1\s\Company.API.Auth'.
Using root namespace 'Company.API.Auth'.
Using project directory 'D:\a\1\s\Company.API.Auth\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
Using environment 'Development'.
Using application service provider from BuildWebHost method on 'Program'.
Found DbContext 'ApplicationContext'.
Finding DbContext classes in the project...
Using context 'ApplicationContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'Company.API.Auth'...
No design-time services were found.
System.InvalidOperationException: The migration 'ΓÇôp' was not found.
   at Microsoft.EntityFrameworkCore.Migrations.MigrationsAssemblyExtensions.GetMigrationId(IMigrationsAssembly assembly, String nameOrId)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateScript(String fromMigration, String toMigration, Boolean idempotent)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.ScriptMigration(String fromMigration, String toMigration, Boolean idempotent, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScriptMigration.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The migration 'ΓÇôp' was not found.
Process completed with exit code 1.

如果我在本地机器上尝试相同的操作,它可以正常工作:

C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth>dotnet ef migrations script -p ..\Company.BaseClassLibrary\Company.BaseClassLibrary.csproj -o %TEMP%\script.sql -i -v
Using project '..\Company.BaseClassLibrary\Company.BaseClassLibrary.csproj'.
Using startup project 'C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\Company.API.Auth.csproj'.
Writing '..\Company.BaseClassLibrary\obj\Company.BaseClassLibrary.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\glen\AppData\Local\Temp\tmpF618.tmp /verbosity:quiet /nologo ..\Company.BaseClassLibrary\Company.BaseClassLibrary.csproj
Writing 'C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\obj\Company.API.Auth.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\glen\AppData\Local\Temp\tmpF7ED.tmp /verbosity:quiet /nologo C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\Company.API.Auth.csproj
dotnet build C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\Company.API.Auth.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.86
dotnet exec --depsfile C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.deps.json --additionalprobingpath C:\Users\glen\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.runtimeconfig.json C:\Users\glen\.nuget\packages\microsoft.entityframeworkcore.tools.dotnet\2.0.0\tools\netcoreapp2.0\ef.dll migrations script -o C:\Users\glen\AppData\Local\Temp\script.sql -i --assembly C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.BaseClassLibrary.dll --startup-assembly C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0\Company.API.Auth.dll --project-dir C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.BaseClassLibrary\ --verbose --root-namespace Company.BaseClassLibrary
Using assembly 'Company.BaseClassLibrary'.
Using startup assembly 'Company.API.Auth'.
Using application base 'C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth\bin\Debug\netcoreapp2.0\netcoreapp2.0'.
Using working directory 'C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.API.Auth'.
Using root namespace 'Company.BaseClassLibrary'.
Using project directory 'C:\Users\glen\source\repos\Company\Company.API.Auth\Company.API.Auth\Company.BaseClassLibrary\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
Using environment 'Development'.
Using application service provider from BuildWebHost method on 'Program'.
Found DbContext 'ApplicationContext'.
Finding DbContext classes in the project...
Using context 'ApplicationContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'Company.API.Auth'...
No design-time services were found.
Writing 'C:\Users\glen\AppData\Local\Temp\script.sql'...

VSTS命令行如下所示,并在我的WebAPI项目的工作目录中运行:

dotnet ef migrations script –p ..\Company.BaseClassLibrary\Company.BaseClassLibrary.csproj -o $(Build.ArtifactStagingDirectory)\Migrations\migration.sql -i -v

任何可能导致此问题的想法?

1 个答案:

答案 0 :(得分:0)

通过在VSTS中使用命令行2.x而不是默认的1.x

解决了这个问题
相关问题