VS2012后部署脚本引用其他几个脚本

时间:2022-12-06 10:45:23

I have created a database project in VS2012. I added database structure. It works fine to publish and compare database.

我在VS2012中创建了一个数据库项目。我添加了数据库结构。它可以很好地发布和比较数据库。

Now on publish I want to automatically load several tables with default data.

现在发布我想自动加载几个具有默认数据的表。

I created five script files with INSERT statements generated from SQL Management Studio. They were added to a Script folder in my database project.

我使用从SQL Management Studio生成的INSERT语句创建了五个脚本文件。它们被添加到我的数据库项目的Script文件夹中。

Then I set BuildAction=PostDeploy. This works fine. BUT from some reason it is only possible to have ONE script set to PostDeploy ....

然后我设置BuildAction = PostDeploy。这很好用。但由于某种原因,只能将一个脚本设置为PostDeploy ....

I realize I can move all scripts into one file. But I have a lot and would really like to group them in separate files to maintain some order.

我意识到我可以将所有脚本移动到一个文件中。但我有很多,并且真的想将它们分组在单独的文件中以维持一些顺序。

I then created one PostDeploy.sql file and tried to reference all other script files from there. The file header gives directions:

然后我创建了一个PostDeploy.sql文件,并尝试从那里引用所有其他脚本文件。文件头给出了方向:

Post-Deployment Script Template                         
----------------------------------------------------------------------------
This file contains SQL statements that will be appended to the build script.
Use SQLCMD syntax to include a file in the post-deployment script.
Example:      :r .\myfile.sql

So I write my file:

所以我写了我的文件:

:r .\MyScript1.sql
:r .\MyScript2.sql
:r .\MyScript3.sql
:r .\MyScript4.sql
:r .\MyScript5.sql

The file complains on wrong syntax.

该文件以错误的语法提出抱怨。

1 个解决方案

#1


75  

It turned out that Visual Studio fooled me with wrong syntax warnings! My setup was perfectly valid.

原来,Visual Studio用错误的语法警告欺骗了我!我的设置完全有效。

To avoid warnings right click anywhere inside the file and choose "Execution Settings - SQLCMD Mode".

要避免警告,请右键单击文件中的任意位置,然后选择“执行设置 - SQLCMD模式”。

There is also a toolbar button named SQLCMD Mode doing the same thing.

还有一个名为SQLCMD Mode的工具栏按钮执行相同的操作。

Here is the menu item in case you can't find the toolbar button: VS2012后部署脚本引用其他几个脚本

这是菜单项,以防您找不到工具栏按钮:

#1


75  

It turned out that Visual Studio fooled me with wrong syntax warnings! My setup was perfectly valid.

原来,Visual Studio用错误的语法警告欺骗了我!我的设置完全有效。

To avoid warnings right click anywhere inside the file and choose "Execution Settings - SQLCMD Mode".

要避免警告,请右键单击文件中的任意位置,然后选择“执行设置 - SQLCMD模式”。

There is also a toolbar button named SQLCMD Mode doing the same thing.

还有一个名为SQLCMD Mode的工具栏按钮执行相同的操作。

Here is the menu item in case you can't find the toolbar button: VS2012后部署脚本引用其他几个脚本

这是菜单项,以防您找不到工具栏按钮: