Как исправить: в конвейере сборки Azure Devops Entity Framework не генерирует сценарий SQL - PullRequest
0 голосов
/ 08 октября 2019

Я пытаюсь подготовить линию сборки Azure для проекта, но сценарий SQL, сгенерированный в Azure Devops, не содержит никакой необходимой схемы данных.

Немного подробнее. Проект находится в ядре Aspnet 2.2 и использует Entity Framework. Когда я запускаю команды локально, я получаю правильные сценарии SQL:

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

Когда я запускаю команды как часть конвейера Azure Devops:

- 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

, вывод только:

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

Вывод из многословия:

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

Есть ли что-то, что я здесь не так делаю?

1 Ответ

0 голосов
/ 04 ноября 2019

Вам нужна папка «Миграции» для генерации скриптов.

Если у вас нет папки Migrations в хранилище, выполните миграцию, прежде чем создавать сценарии:

dotnet ef migrations add X
...