tfs 文件系统部署_使用SQL Server数据工具和使用自定义工作流文件的TFS部署到多个数据库...
tfs 文件系统部署
In the previous blog post : Deployment to several databases using SQL Server Data Tools and Team foundation Server I illustrated how it is possible to use TFS and a batch file to deploy a database to several SQL Server instances or to deploy several SQL Server databases to several instances. The main way to achieve that in the previous post was using a batch file. For more information about this technique please have a look at that blog post.
在上一篇博客文章: 使用SQL Server数据工具和Team Foundation Server部署到多个数据库中,我说明了如何使用TFS和批处理文件将数据库部署到多个SQL Server实例或将几个SQL Server数据库部署到几个实例。 在上一篇文章中,实现此目标的主要方法是使用批处理文件。 有关此技术的更多信息,请参阅该博客文章。
In this post on the other hand I will demonstrate how the same functionality can be achieved using a Windows Workflow Foundation file (xaml) deployment file and Team Foundation Server.
另一方面,在本文中,我将演示如何使用Windows Workflow Foundation文件(xaml)部署文件和Team Foundation Server实现相同的功能。
使用Windows Workflow Foundation文件 (Using a Windows Workflow Foundation file)
In Team Foundation build the processes are controlled by Windows Workflow Foundation files. In the same way that we could use a batch file to call SQLPackage.exe in various ways, we can use a Windows Workflow Foundation file to call SQLPackage.exe. This option is the most complex but also the most flexible.
在Team Foundation构建中,过程由Windows Workflow Foundation文件控制。 以与可以使用批处理文件以各种方式调用SQLPackage.exe相同的方式,可以使用Windows Workflow Foundation文件来调用SQLPackage.exe。 此选项最复杂,但也最灵活。
Use this option when :
在以下情况下使用此选项:
- You want to deploy a database to several SQL Server instances upon successful build 您希望在成功构建后将数据库部署到多个SQL Server实例
- You want to deploy several databases to one or several SQL Server instances upon successful build 您希望在成功构建后将多个数据库部署到一个或多个SQL Server实例
The first step in this setup is to make a custom template and workflow project for the build definition.
此设置的第一步是为构建定义创建自定义模板和工作流项目。
创建自定义模板 (Creating a custom template)
Those few steps will let you create a custom template :
这几个步骤可让您创建自定义模板:
-
Create a workflow activity library project in your solution (you need to do that in the context of a project otherwise you might encounter problems when editing the template)
在解决方案中创建工作流程活动库项目(您需要在项目的上下文中执行此操作,否则在编辑模板时可能会遇到问题)
-
Go back to your Team Explorer pane and choose Build definitions
返回到“团队资源管理器”窗格,然后选择“构建定义”
-
Create a new build definition or use an existing one.
创建一个新的构建定义或使用现有的定义。
-
Setup the build definition to Continuous Integration – Build each check-in
将构建定义设置为持续集成–构建每个签入
-
On the Source settings of the definition choose the project(s) that you want to build and deploy
在定义的“源”设置上,选择要构建和部署的项目
-
On the build defaults pane pick the right controller and a shared folder to where the build output will be copied
在构建默认值窗格上,选择合适的控制器和一个共享文件夹,将构建输出复制到该共享文件夹中
- The next pane, the Process pane is where things are getting really exciting ???? 接下来的窗格是“处理”窗格,这里的事情真的令人兴奋????
修改Windows Workflow Foundation模板文件 (Modifying the Windows Workflow Foundation template file)
In the Process pane under the Build Process Template click on Show Details and download the default.xaml file
在“ 构建过程模板”下的“ 过程”窗格中,单击“ 显示详细信息”并下载default.xaml文件
This is the file, that we are going to customize, so save it somewhere where it can be found again and under a meaningful name!!
这是我们将要自定义的文件,因此将其保存在可以再次找到它的某个位置,并使用有意义的名称!!
-
In the previously created Activity Library project delete the default xaml file created and add the new downloaded. This file shouldn’t be copied to the output directory.
在先前创建的活动库项目中,删除创建的默认xaml文件并添加新下载的文件。 该文件不应复制到输出目录。
-
Open the file to view the different workflow elements and add your own custom ones.
打开文件以查看不同的工作流程元素并添加自己的自定义元素。
This the overall build template without any changes. It looks small but don’t be fooled once expanded they are many many steps that make the process a very complex workflow indeed.
这样整个构建模板没有任何更改。 它看起来很小,但一旦扩展就不会被愚弄,它们有许多步骤,确实使流程成为非常复杂的工作流。
Under Run on agent go and find the Run optional Script after MSBuild block this is where you need to put your own custom functionality. The right path to the place in the template is:
在“在代理上运行”下,找到“在MSBuild之后运行可选脚本”块,这是您需要放置自定义功能的地方。 模板中该位置的正确路径是:
Overall build process ➙ Run on Agent ➙ Try ➙ Compile, Test, and Publish. Right after the activity Run optional Script after MSBuild.
总体构建过程on在代理上运行➙尝试➙编译,测试和发布。 活动结束后,在MSBuild之后运行可选脚本 。
Right there :
在那里 :
将自定义构建基块添加到工作流模板 (Adding custom building blocks to the Workflow template)
Once you’ve found the right place to hook in, expand the toolbox on your project. It will eventually need to load and you will see a myriad of different components ready to be added to your workflow template.
找到合适的位置后,在项目上展开工具箱。 最终将需要加载它,您将看到准备将许多不同的组件添加到工作流模板中。
-
Find the Run Script activity in the toolbox. It is under Team Foundation Build Activities section of the toolbox
在工具箱中找到“ 运行脚本”活动。 它在工具箱的“ 团队基础构建活动”部分下
-
Add this activity right after the Run optional Script after MSBuild activity and give it a meaningful name in the Properties pane. The rest of the steps will take place in the Properties pane and is the same procedure than when using a Batch file (like described in my previous post). The first mandatory step in a RunScript activity is to specify what is the FilePath of the program to run. In this case we need to find SQLPackage.exe which usually resides there :
“C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\sqlpackage.exe”
Once you get the FilePath you need the arguments to ensure the deployment.
In my case I use :
“/a:Publish /pr:$(TF_BUILD_SOURCESDIRECTORY)\Projects\ContinuousIntegration\ContinuousIntegration\ContinuousIntegration.publish.xml /sf:$(TF_BUILD_BINARIESDIRECTORY)\ContinuousIntegration.dacpac”
So the tricky part is to build those command lines. For doing that you have to consider several options and how you setup your project or projects Output Location. The options for the Output Location field are either PerProject or SingleProject in your custom build definition. I usually use a SingleProject option to avoid having this kind of problems.
在“在MSBuild之后运行可选脚本”活动之后立即添加此活动,并在“属性”窗格中为其赋予有意义的名称。 其余步骤将在“属性”窗格中进行,并且与使用批处理文件时的过程相同(如我之前的文章中所述)。 RunScript活动中的第一步必需步骤是指定要运行的程序的FilePath 。 在这种情况下,我们需要找到通常驻留在其中SQLPackage.exe:
“ C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ Extensions \ Microsoft \ SQLDB \ DAC \ 120 \ sqlpackage.exe”
一旦获得FilePath,就需要使用参数来确保部署。
就我而言,我使用:
“ / a:发布/pr:$(TF_BUILD_SOURCESDIRECTORY)\Projects\ContinuousIntegration\ContinuousIntegration\ContinuousIntegration.publish.xml /sf:$(TF_BUILD_BINARIESDIRECTORY)\ContinuousIntegration.dacpac”
因此,棘手的部分是构建这些命令行。 为此,您必须考虑几个选项以及如何设置项目或项目“ 输出位置” 。 自定义构建定义中“ 输出位置”字段的选项是PerProject或SingleProject 。 我通常使用SingleProject选项来避免出现此类问题。
-
If you have chosen PerProject your command line should look like that (on a single line):
“/a:Publish /pr:%TF_BUILD_BINARIESDIRECTORY%\<Project Name>\<Publish profile file>.publish.xml /sf:%TF_BUILD_BINARIESDIRECTORY%\<Project Name>\<DACPAC file name>.dacpac”
如果选择了PerProject,则命令行应如下所示(单行):
“ / a:发布/ pr:%TF_BUILD_BINARIESDIRECTORY%\ <项目名称> \ <发布配置文件> .publish.xml / sf:%TF_BUILD_BINARIESDIRECTORY%\ <项目名称> \ <DACPAC文件名> .dacpac”
-
If you are using a SingleProject deployment then the command line will omit the project name:
“/a:Publish /pr:%TF_BUILD_BINARIESDIRECTORY%\<Publish profile file>.publish.xml /sf:%TF_BUILD_BINARIESDIRECTORY%\<DACPAC file name>.dacpac”
如果使用的是SingleProject部署,则命令行将省略项目名称:
“ / a:发布/ pr:%TF_BUILD_BINARIESDIRECTORY%\ <发布配置文件> .publish.xml / sf:%TF_BUILD_BINARIESDIRECTORY%\ <DACPAC文件名> .dacpac”
-
Option 2 : Without a Publish profile, you will need to specify the database details in the command line file:
“/a:Publish /tcs:””Data Source=<SQL Server>;Integrated Security=true;Initial Catalog=<Database Name>;Pooling=false”” /sf:%TF_BUILD_BINARIESDIRECTORY% \<DACPAC file name>.dacpac”
选项2 :如果没有发布配置文件,则需要在命令行文件中指定数据库详细信息:
“ / a:发布/ tcs:”“数据源= <SQL Server>; 集成安全性= true;初始目录= <数据库名称>; Pooling = false”” / sf:%TF_BUILD_BINARIESDIRECTORY%\ <DACPAC文件名> .dacpac”
-
And the same command this time with a setting of PerProject :
“/a:Publish /tcs:””Data Source=<SQL Server>;Integrated Security=true;Initial Catalog=<Database Name>;Pooling=false”” /sf:%TF_BUILD_BINARIESDIRECTORY% \<Project Name>\<DACPAC file name>.dacpac”
这次使用PerProject设置相同的命令:
“ / a:发布/ tcs:”“数据源= <SQL Server>; 集成安全性= true;初始目录= <数据库名称>; Pooling = false”” / sf:%TF_BUILD_BINARIESDIRECTORY%\ <项目名称> \ <DACPAC文件名> .dacpac”
For each database that you want to publish or each location you want to publish to repeat the steps above, starting at step 1 of “Adding custom building blocks to the Workflow template”
对于要发布的每个数据库或要发布的每个位置,重复上述步骤,从“向工作流模板添加自定义构件”的步骤1开始
After that remember to check in your Build template and ensure that it is used in the Customized build template.
之后,请记住签入您的构建模板,并确保在自定义构建模板中使用了它。
On the Process Pane of the Build Template click New out for the Build Process File and pick the Windows Workflow Foundation file that you’ve just build.
在“生成模板”的“过程”窗格上,单击“新建”以生成“生成过程文件”,然后选择刚刚构建的Windows Workflow Foundation文件。
This should do the trick and upon if you use this customized Build Template upon your next checkin you should be able to deploy your database(s) to the specified instance(s).
这应该可以解决问题,并且如果您在下次签入时使用此自定义的生成模板,则应该能够将数据库部署到指定的实例。
In an upcoming post I will explain how to achieve this by using Visual Studio Online. They are a few minor differences and some breaking changes. More information about Visual Studio Online
在即将发布的文章中,我将解释如何使用Visual Studio Online实现此目的。 它们是一些细微的差异和一些重大变化。 有关Visual Studio Online的更多信息
Happy deploying !!
部署愉快!
tfs 文件系统部署