简体   繁体   English

Sql Project Publish 替换 Deploy - 如何抑制版本控制并挂接到 tfs build

[英]Sql Project Publish replaces Deploy - how to supress versioning and hook into tfs build

We're using the Sql Server 2012 SSDT which removed the deploy option in Visual Studio for the database projects (now sql projects).我们正在使用 Sql Server 2012 SSDT,它删除了 Visual Studio 中数据库项目(现在是 sql 项目)的部署选项。 We'd like to automate the Publish step as we had for deploy, but it's not clear how to do this.我们希望像部署时那样自动执行发布步骤,但不清楚如何执行此操作。 so thA couple of questions:所以有几个问题:

  1. I've added the.publish.xml to the project (after the first manual publish, checking add to project).我已经将 the.publish.xml 添加到项目中(在第一次手动发布之后,选中添加到项目)。 Even after that, and setting it to the default, when I double click it, it builds, but always pops up settings window, where I need to click the "Publish" button to continue.即使在那之后,并将其设置为默认值,当我双击它时,它也会构建,但总是弹出设置 window,我需要在其中单击“发布”按钮才能继续。 Is there a setting that would skip this prompt and use the current values?是否有可以跳过此提示并使用当前值的设置?

  2. It seems that each publish generates a version of the sql output. How can I suppress this- ie overwrite the base file each time?似乎每次发布都会生成 sql output 的一个版本。我怎样才能抑制这种情况——即每次都覆盖基本文件?

  3. And lastly, any pointers for updating the build to use the new project type and publish command for the automated builds would be appreciated.最后,对于更新构建以使用新项目类型和自动构建发布命令的任何指示,我们将不胜感激。

How to restore the Deploy option: (Visual Studio 2010/2012 only -- this is no longer supported in Visual Studio 2013)如何恢复 Deploy 选项:(仅限 Visual Studio 2010/2012——Visual Studio 2013 不再支持此选项)

The Deploy option is still present but for some reason it's not available in the menus.部署选项仍然存在,但由于某种原因它在菜单中不可用。 (Cursed Visual Studio team:) I've worked around this by adding the Deploy option to one of the toolbars as follows: (该死的 Visual Studio 团队:)我已经通过将 Deploy 选项添加到其中一个工具栏来解决这个问题,如下所示:

  1. Click the arrow on the right-hand side of a toolbar.单击工具栏右侧的箭头。
  2. Click "Add or Remove Buttons", then Customize.单击“添加或删除按钮”,然后单击“自定义”。
  3. In the Customize dialog click Add Command.在自定义对话框中单击添加命令。
  4. Select the "Build" category, then select the "Deploy Selection" command. Select “构建”类别,然后 select “部署选择”命令。
  5. After saving your selection the "Deploy [project name]" option will appear on the toolbar.保存您的选择后,“部署 [项目名称]”选项将出现在工具栏上。 You'll need to select your project in Solution Explorer for the button to become enabled.您需要在解决方案资源管理器中 select 您的项目才能启用该按钮。

Note that the deployment settings are different than the publish settings.请注意,部署设置不同于发布设置。 The deployment settings are configured in the project's properties on the Debug tab.部署设置在“调试”选项卡上的项目属性中配置。


To answer your questions about the Publish option:要回答有关发布选项的问题:

1) How to use a specific publish file by default and avoid the annoying prompt 1)如何默认使用特定的发布文件并避免烦人的提示

I don't think there's a way around this.我认为没有办法解决这个问题。

2) How to publish the entire database, not just the changes 2)如何发布整个数据库,而不仅仅是更改

Open your.publish.xml file in a text editor and add <AlwaysCreateNewDatabase>true</AlwaysCreateNewDatabase> .在文本编辑器中打开 your.publish.xml 文件并添加<AlwaysCreateNewDatabase>true</AlwaysCreateNewDatabase>

For example:例如:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TargetDatabaseName>MyDatabase</TargetDatabaseName>
    <DeployScriptFileName>MyDatabaseProject.sql</DeployScriptFileName>
    <TargetConnectionString>Data Source=localhost\SQL2012;Integrated Security=True;Pooling=False</TargetConnectionString>
    <PublishDependentProjects>False</PublishDependentProjects>
    <ProfileVersionNumber>1</ProfileVersionNumber>
    <AlwaysCreateNewDatabase>true</AlwaysCreateNewDatabase>
  </PropertyGroup>
</Project>

3) Command-line syntax for automated builds 3) 自动化构建的命令行语法

First build your project with msbuild as you normally would so that the.dacpac file is created in the bin.首先像往常一样使用 msbuild 构建项目,以便在 bin 中创建 .dacpac 文件。

Then use sqlpackage.exe to publish using your.publish.xml file:然后使用sqlpackage.exe使用 your.publish.xml 文件进行发布:

C:\Program Files\Microsoft Visual Studio 10.0\Microsoft SQL Server Data Tools\sqlpackage.exe /Action:Publish /SourceFile:C:\[path to my project]\bin\Debug\MyDatabaseProject.dacpac /Profile:C:\[path to my project]\MyDatabaseProject.publish.xml

Note that the path to sqlpackage.exe may be different.请注意,sqlpackage.exe 的路径可能不同。

The best way I have found to automate the deployment of SSDT database projects is to use msbuild. Originally we were using VSTSDB and used msbuild against the *.dbproj file.我发现自动部署 SSDT 数据库项目的最佳方法是使用 msbuild。最初我们使用 VSTSDB 并针对 *.dbproj 文件使用 msbuild。 As it turned out the arguments for deploying sqlproj files is exactly the same.事实证明,用于部署 sqlproj 文件的 arguments 完全相同。

Because the old argument list works for us, I didnt swap to using the public.xml file style.因为旧的参数列表对我们有用,所以我没有换成使用 public.xml 文件样式。 There quite a bit of documentation for the vsdbcmd.exe and msbuild against dbproj.针对 dbproj 的 vsdbcmd.exe 和 msbuild 有相当多的文档。 I would use that as reference.我会用它作为参考。

Here's argument list, and execution output as we define it for FinalBuilder execution这是我们为 FinalBuilder 执行定义的参数列表和执行 output

[ MSBuild Project [ C:\xx\xxx\xx\xx\MyProject.sqlproj ] ]
  Configuration : Release
  OutDir : C:\Builds\1\xxxxx\builddefname\Binaries\Release\
  DeployToDatabase : True
  TargetDatabase : ExistingDatabaseName
  TargetConnectionString : Data source=.;Integrated Security=SSPI;**
  Build started 3/23/2012 2:17:08 PM.
  Deployment script generated to:
  C:\Builds\1\xxxx\builddefname_FB\Binaries\Release\MyProject.sql
  Dropping FK_at_lusys_assetCategory_at_lusys_image...
  Creating FK_dcb28374eeabe8e715038984419...
  Creating FK_d82897e4acd966d4b136c242cef...
  Checking existing data against newly created constraints
  Update complete.
  Done Building Project "C:\xxx\xxxxxxx\xxxxxxxxx\MyProject.sqlproj" (Deploy target(s)).
  Build succeeded.
  0 Warning(s)
  0 Error(s)

and putting together the msbuild command line looks like this:将 msbuild 命令行放在一起看起来像这样:

msbuild XXX.sqlproj /target:Deploy /p:Configuration=xxx;OutDir=xxx;DeployToDatabase=True;TargetDatabase=xxxx;TargetConnectionString="xxxxx";AlwaysCreateNewDatabase=True

A bit late to the party, I admit, but maybe this will help others who stumble across this discussion.晚会有点晚了,我承认,但也许这会帮助那些偶然发现这个讨论的人。 My company is presently moving to VS2012 and we have all three of the same issues as Keith.我的公司目前正在迁移到 VS2012,我们遇到了与 Keith 相同的三个问题。 I have found workarounds for #1 and #2.我找到了#1 和#2 的解决方法。

For #1, I use AutoHotKey to monitor for the existence of the publish window, and automatically click the "Create Script" button.对于 #1,我使用AutoHotKey来监视发布 window 是否存在,并自动单击“创建脚本”按钮。 You could of course have the script automatically click the "Publish" button instead.您当然可以让脚本自动单击“发布”按钮。 In this example if the publish profile is not "XYZ" (I always prefer manual intervention for production server deployments) then go ahead and send an Alt+G to generate the script.在此示例中,如果发布配置文件不是“XYZ”(我总是更喜欢手动干预生产服务器部署),则提前输入 go 并发送 Alt+G 以生成脚本。

#Persistent
SetTimer, ClosePopups, 5000

return

ClosePopups:
if WinExist("Publish Database ")
{
    WinActivate, Publish Database
    WinGetTitle, TitleText, A
    If not TitleText = "Publish Database XYZ.publish.xml" {
        Send, !G
    }
}
return 

For #2, every time we publish it increments the filename with a number suffix and we end up with lots of files in our deployment folder.对于 #2,每次我们发布时都会增加带有数字后缀的文件名,最终我们的部署文件夹中会出现大量文件。 I just used pre-build events to clear out the.sql and.txt files before the build:我只是在构建之前使用预构建事件清除了 .sql 和 .txt 文件:

if exist "$(ProjectDir)$(OutputPath)*.publish.sql" del $(ProjectDir)$(OutputPath)*.publish.sql
if exist "$(ProjectDir)$(OutputPath)*.txt" del $(ProjectDir)$(OutputPath)*.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM