Миграция .NET Core EF через VSTS - PullRequest
0 голосов
/ 04 июня 2018

Когда я пытаюсь создать скрипт миграции локально на моей машине, он работает нормально.Тем не менее, в 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 голосов
/ 04 июня 2018

Решено с помощью командной строки 2.x в VSTS, а не по умолчанию 1.x

...