azure-devops - 如何生成 DACPAC 文件

标签 azure-devops dacpac

我正在尝试通过 IIS 网站和 SQL 部署在 Azure DevOps 中部署我的项目。但是,我正在努力部署 SQL 部分,因为我的构建工件中没有 .dacpac 文件。我如何生成它,因为我尝试过的任何选项都以过程失败而告终。

附言由于限制,我无权访问我正在部署的 VM。我可以访问数据库,因为我在机器上标记为 DBO。

我的问题也是,我是否需要每次都通过构建生成这个 DACPAC 文件,或者它只能生成一次,存储在机器上,我从部署过程指向该文件?

感谢您的帮助!

最佳答案

However I am struggling with deploying SQL part as I do not have a .dacpac file in my build artifacts. How do I generate this as any option that I have tried it ended up with failing of the process. I can access database as I marked as DBO on the machine.

  1. 首先,您必须通过导入实时数据库的对象,使用 SSDT(或 Azure Data Studio 内部预览版)创建 SQL Server 数据库项目。

  2. 然后将数据库项目放入存储库

  3. 管道(经典或 yaml)具有构建任务 MSBuild@1。这是一个 YAML 示例。它生成 dacpac

- task: MSBuild@1
    displayName: 'Build solution YourDatabase.sln'
    inputs:
      solution: 'src/YourDatabase.sln'

此任务编译数据库项目并生成 dacpac 文件

  1. 然后要提取生成的文件:
- task: CopyFiles@2
    displayName: 'Extract DACPACs'
    inputs:
        CleanTargetFolder: false
        SourceFolder: '$(agent.builddirectory)\s\src\YourDatabase\bin\Debug\'
        Contents: '*.dacpac'
        TargetFolder: '$(build.artifactstagingdirectory)'
  1. 最后,作为人工制品发布
  - task: PublishPipelineArtifact@1
    displayName: 'Publish Artifact'
    inputs:        
        targetPath: '$(build.artifactstagingdirectory)'
        artifact: 'drop'
  1. dacpac 的部署是最终目标,可以使用 SqlDacpacDeploymentOnMachineGroup@0 完成,但是,这超出了原始问题的范围

My question is also, do I need to generate this DACPAC file through build every time or it can be generated only once, stored on machine, and I point from deployment process to that file?

视情况而定。

  • 经典管道将 BUILD 和 RELEASE 阶段分开。在这种情况下,您可以构建一次并在未来的许多版本中重用该 dacpac。

  • 在多阶段 yaml 管道的情况下,每个管道运行都会触发构建和部署阶段,这是很常见的,因为它们仍然属于同一个管道并作为单个单元工作运行。

关于azure-devops - 如何生成 DACPAC 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63992521/

相关文章:

azure - 如何在 azure bicep 部署模板中获取 Linux 应用服务的主机 url

docker - VSTS docker撰写任务

powershell - 通过 powershell 脚本将 Dacpac 包部署到 Azure SQL Server

c# - 尝试部署 dapac : The path specified by File Ggroup FG. mdf 文件不在有效目录中时,SQL Linux docker 容器抛出错误

sql - VSTS 构建不会拾取 dacpac 文件(云中的托管代理)

sql-server - 将多个 dacpac 文件部署到单个数据库

github - 从 GitHub 导入到 Azure DevOps 时出现“克隆 URL 不正确”

asp.net-core - 在 VSO 构建上运行 DNU Restore

versioning - 如何从 DACPAC 文件中获取版本号

azure-devops - Azure DevOps多阶段管道部署到特定环境