首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修复方法:在Azure Devops中构建管道实体框架不生成SQL脚本

修复方法:在Azure Devops中构建管道实体框架不生成SQL脚本
EN

Stack Overflow用户
提问于 2019-10-08 19:30:22
回答 1查看 699关注 0票数 1

我正在尝试为一个项目准备azure构建管道,但Azure Devops中生成的SQL脚本不包含任何必需的数据方案。

更多细节。项目位于Aspnet核心2.2中,并使用Entity Framework。当我在本地运行命令时,我收到了正确的SQL脚本:

代码语言:javascript
复制
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管道的一部分运行时:

代码语言:javascript
复制
- 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

输出结果仅为:

代码语言:javascript
复制
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

详细输出:

代码语言:javascript
复制
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

这里有什么地方我做错了吗?

EN

回答 1

Stack Overflow用户

发布于 2019-11-04 18:35:33

您需要“Migrations”文件夹来生成脚本。

如果您在存储库中没有Migrations文件夹,请在生成脚本之前进行迁移:

代码语言:javascript
复制
dotnet ef migrations add X
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58285511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档