dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.83k stars 3.2k forks source link

Can't build migration script on VSTS Only #12219

Closed glenmaroney closed 2 years ago

glenmaroney commented 6 years ago

When I try to build a migration script locally on my machine, it works fine. However, in VSTS Build, I get a strange exception:

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

Stack trace:
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.

Steps to reproduce

The following command is used in the VSTS pipeline and executes in the working directory for a WebAPI project: dotnet ef migrations script –p ..\Company.BaseClassLibrary\Company.BaseClassLibrary.csproj -o $(Build.ArtifactStagingDirectory)\Migrations\migration.sql -i -v

Further technical details

EF Core version: 2.0.0 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 IDE: Visual Studio 2017 15.4

glenmaroney commented 6 years ago

The corresponding log from my local machine:

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'...

glenmaroney commented 6 years ago

This isn't an issue with EF so closing it. Problem was solved when using VSTS build command line v2.x rather than 1.x