Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Generate Migration Scripts #11645


User avatar
0
mayankm created

I'm using .Net core + Angular Merge solution.

I'm trying to create database migration script using this method: https://docs.aspnetzero.com/en/aspnet-core-mvc/latest/Setting-Up-an-Azure-Pipeline-Mvc-Core#generate-migration-scripts-task

I've following setting for the task:

but getting error as below.

Raw log:

Starting: Generate Migration Scripts ============================================================================== Task : Entity Framework Core Migrations Script Generator Description : Tool for projects that use Entity Framework Core Code-First. Generates migration scripts which can be used to update a database (for instance with the task 'Azure SQL Database Deployment'). Version : 1.0.2 Author : PEK's Productions Help : More Information ============================================================================== Project path: D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\Synegrate.PatriotWorld.EntityFrameworkCore.csproj Start-up project path: D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\Synegrate.PatriotWorld.Web.Host.csproj Target folder: D:\a\1\a/migrations Number of database contexts: 1 All migrations will be used. Will not try to install dotnet-ef. If you are using .NET Core 3 you could enable 'Install dependencies for .NET Core 3' to do this automatically. If you are using .NET Core 2 you may need to add the 'Use .NET Core' before running this task. See here for more details: https://github.com/pekspro/EF-Migrations-Script-Generator-Task Generating migration script for PatriotWorldDbContext in project D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\Synegrate.PatriotWorld.EntityFrameworkCore.csproj Projects will not be built before scripts are generated. Default build configuration will be used. The script will be idempotent. "C:\Program Files\dotnet\dotnet.exe" ef migrations script --project D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\Synegrate.PatriotWorld.EntityFrameworkCore.csproj --startup-project D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\Synegrate.PatriotWorld.Web.Host.csproj --output D:\a\1\a/migrations/PatriotWorldDbContext.sql --context PatriotWorldDbContext --verbose --no-build --idempotent Using project 'D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\Synegrate.PatriotWorld.EntityFrameworkCore.csproj'. Using startup project 'D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\Synegrate.PatriotWorld.Web.Host.csproj'. Writing 'D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\obj\Synegrate.PatriotWorld.EntityFrameworkCore.csproj.EntityFrameworkCore.targets'... dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmp7096.tmp /verbosity:quiet /nologo D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\Synegrate.PatriotWorld.EntityFrameworkCore.csproj Writing 'D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\obj\Synegrate.PatriotWorld.Web.Host.csproj.EntityFrameworkCore.targets'... dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmp7431.tmp /verbosity:quiet /nologo D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\Synegrate.PatriotWorld.Web.Host.csproj dotnet exec --depsfile D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\bin\Debug\net6.0\Synegrate.PatriotWorld.Web.Host.deps.json --additionalprobingpath C:\Users\VssAdministrator.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" C:\Users\VssAdministrator.nuget\packages\dotnet-ef\7.0.8\tools\net6.0\any\tools\netcoreapp2.0\any\ef.dll migrations script --output D:\a\1\a/migrations/PatriotWorldDbContext.sql --context PatriotWorldDbContext --idempotent --assembly D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\bin\Debug\net6.0\Synegrate.PatriotWorld.EntityFrameworkCore.dll --project D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\Synegrate.PatriotWorld.EntityFrameworkCore.csproj --startup-assembly D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\bin\Debug\net6.0\Synegrate.PatriotWorld.Web.Host.dll --startup-project D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\Synegrate.PatriotWorld.Web.Host.csproj --project-dir D:\a\1\s\src\Synegrate.PatriotWorld.EntityFrameworkCore\ --root-namespace Synegrate.PatriotWorld --language C# --framework net6.0 --working-dir D:\a\1\s --verbose The specified deps.json [D:\a\1\s\src\Synegrate.PatriotWorld.Web.Host\bin\Debug\net6.0\Synegrate.PatriotWorld.Web.Host.deps.json] does not exist ##[error]The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 2147516545 Finishing: Generate Migration Scripts


4 Answer(s)
  • User Avatar
    0
    sedulen created

    @mayankm,

    I am able to successfully generate EF migration scripts. However, I am using a different Task in my Azure DevOps pipeline. I am using the .NET Core task, with a command of custom

    command: custom custom command: ef arguments: migrations script -i -p src/$(ProjectName).EntityFrameworkCore/$(ProjectName).EntityFrameworkCore.csproj -o $(Build.ArtifactStagingDirectory)/Migrations/$(ProjectName).Core_migrations_$(Build.BuildNumber).sql

    I like variables in my pipelines, so I have the ProjectName as a variable.

    once that task completes, I have 2 subsequent Azure DevOps tasks in my pipeline for "Copy SQL files into Sql Artifact" and "Publish Sql Artifact".

    "Copy SQL files into Sql Artifact" is a Copy Files task

    source folder: sql contents: ****** target folder: $(Build.ArtifactStagingDirectory)/Migrations/

    "Publish Sql Artifact" is a Publish Build Artifacts task

    path to publish: $(Build.ArtifactStagingDirectory)/Migrations/ artifact name: SQL artifact publish location: Azure Pipelines

    let me know if that works for you, -Brian

  • User Avatar
    0
    mayankm created

    Thanks Brain for your valuable details but it seems similar error when I don't choose startup project as not sure if it is becuase I'm using Angular + .net core merged project.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mayankm

    The suggested approach is to run Migrator console application to update your database. Could you also publish the Migrator app and run it on your target database ?

    While running the Migrator app, pass "-s" parameter so it will not wait for any user input.

  • User Avatar
    0
    mayankm created

    Hi @sedulen, @ismcagdas thanks. I managed to run using separate job for migration. Thank you!