1
votes

I'm trying to prepare the azure build pipleline for a project, but the SQL script generated in Azure Devops doesn't contain any required data scheme.

Little more details. Project is in Aspnet core 2.2 and use Entity Framework. When I run the commands locally I receive correct SQL scripts:

dotnet ef migrations script -i -c TrainersContext -p .\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj -o .\migrations\TrainersContextScripts.sql -s .\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj

dotnet ef migrations script -i -c PersonalTrainerWebContext -p .\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj -o .\migrations\PersonalTrainerWebContextScripts.sql -s .\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj

When I run the commands as part of Azure Devops pipeline:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      dotnet ef migrations script -i -v -c PersonalTrainerWebContext -p $(Build.SourcesDirectory)\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj -o $(build.artifactstagingdirectory)\migrations\PersonalTrainerWebContextScripts.sql -s $(Build.SourcesDirectory)\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj
      dotnet ef migrations script -i -v -c TrainersContext -p $(Build.SourcesDirectory)\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj -o $(build.artifactstagingdirectory)\migrations\TrainersContextScripts.sql -s $(Build.SourcesDirectory)\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj

the output is only:

IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
BEGIN
    CREATE TABLE [__EFMigrationsHistory] (
        [MigrationId] nvarchar(150) NOT NULL,
        [ProductVersion] nvarchar(32) NOT NULL,
        CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
    );
END;

GO

Output from verbose:

Successfully installed the ASP.NET Core HTTPS Development Certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only). For establishing trust on other platforms refer to the platform specific documentation.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
Using project 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj'.
Using startup project 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj'.
Writing 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\obj\PersonalTrainer.WebApp.Core.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpCD60.tmp /verbosity:quiet /nologo d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj
Writing 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\obj\PersonalTrainer.WebApp.Core.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpD32D.tmp /verbosity:quiet /nologo d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj
dotnet build d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj /verbosity:quiet /nologo

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

Time Elapsed 00:00:11.45
dotnet exec --depsfile d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.deps.json --additionalprobingpath C:\Users\VssAdministrator\.nuget\packages --additionalprobingpath C:\Microsoft\Xamarin\NuGet --additionalprobingpath C:\hostedtoolcache\windows\dotnet\sdk\NuGetFallbackFolder --runtimeconfig d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.runtimeconfig.json C:\hostedtoolcache\windows\dotnet\sdk\2.2.203\DotnetTools\dotnet-ef\2.2.4\tools\netcoreapp2.2\any\tools\netcoreapp2.0\any\ef.dll migrations script -i -c PersonalTrainerWebContext -o d:\a\1\a\migrations\PersonalTrainerWebContextScripts.sql --assembly d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.dll --startup-assembly d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.dll --project-dir d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\ --language C# --working-dir D:\a\1\s --verbose --root-namespace PersonalTrainer.WebApp.Core
Using assembly 'PersonalTrainer.WebApp.Core'.
Using startup assembly 'PersonalTrainer.WebApp.Core'.
Using application base 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2'.
Using working directory 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core'.
Using root namespace 'PersonalTrainer.WebApp.Core'.
Using project directory 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding IWebHost accessor...
Using environment 'Development'.
Using application service provider from IWebHost accessor on 'Program'.
Found DbContext 'PersonalTrainerWebContext'.
Found DbContext 'TrainersContext'.
Finding DbContext classes in the project...
Using context 'PersonalTrainerWebContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'PersonalTrainer.WebApp.Core'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'PersonalTrainer.WebApp.Core'...
No design-time services were found.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 2.2.4-servicing-10062 initialized 'PersonalTrainerWebContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MigrationsAssembly=PersonalTrainer.WebApp.Core 
Writing 'd:\a\1\a\migrations\PersonalTrainerWebContextScripts.sql'...
Using project 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj'.
Using startup project 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj'.
Writing 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\obj\PersonalTrainer.WebApp.Core.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmpC9B.tmp /verbosity:quiet /nologo d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj
Writing 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\obj\PersonalTrainer.WebApp.Core.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\VssAdministrator\AppData\Local\Temp\tmp10F2.tmp /verbosity:quiet /nologo d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj
dotnet build d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\PersonalTrainer.WebApp.Core.csproj /verbosity:quiet /nologo

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

Time Elapsed 00:00:04.72
dotnet exec --depsfile d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.deps.json --additionalprobingpath C:\Users\VssAdministrator\.nuget\packages --additionalprobingpath C:\Microsoft\Xamarin\NuGet --additionalprobingpath C:\hostedtoolcache\windows\dotnet\sdk\NuGetFallbackFolder --runtimeconfig d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.runtimeconfig.json C:\hostedtoolcache\windows\dotnet\sdk\2.2.203\DotnetTools\dotnet-ef\2.2.4\tools\netcoreapp2.2\any\tools\netcoreapp2.0\any\ef.dll migrations script -i -c TrainersContext -o d:\a\1\a\migrations\TrainersContextScripts.sql --assembly d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.dll --startup-assembly d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2\PersonalTrainer.WebApp.Core.dll --project-dir d:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\ --language C# --working-dir D:\a\1\s --verbose --root-namespace PersonalTrainer.WebApp.Core
Using assembly 'PersonalTrainer.WebApp.Core'.
Using startup assembly 'PersonalTrainer.WebApp.Core'.
Using application base 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\bin\Debug\netcoreapp2.2'.
Using working directory 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core'.
Using root namespace 'PersonalTrainer.WebApp.Core'.
Using project directory 'd:\a\1\s\WebApplication\PersonalTrainer.WebApp.Core\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding IWebHost accessor...
Using environment 'Development'.
Using application service provider from IWebHost accessor on 'Program'.
Found DbContext 'PersonalTrainerWebContext'.
Found DbContext 'TrainersContext'.
Finding DbContext classes in the project...
Using context 'TrainersContext'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 2.2.4-servicing-10062 initialized 'TrainersContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MigrationsAssembly=PersonalTrainer.WebApp.Core 
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'PersonalTrainer.WebApp.Core'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'PersonalTrainer.WebApp.Core'...
No design-time services were found.
Writing 'd:\a\1\a\migrations\TrainersContextScripts.sql'...
##[section]Finishing: PowerShell

Is there anything I do wrong here?

1

1 Answers

0
votes

You need the 'Migrations' folder to generate the scripts.

If you don't have the Migrations folder in the repository make the migrations before generate the scripts:

dotnet ef migrations add X