Visual Studio 2010数据库项目部署到不同的环境

编程入门 行业动态 更新时间:2024-10-07 08:32:19
本文介绍了Visual Studio 2010数据库项目部署到不同的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个数据库项目,它对我的​​本地MSSQL 2008数据库很好。它在脚本/后部署下有一个脚本,进入设置表,以及其他表。我有每个表1个文件,例如。一个Setting.sql文件,用于将数据插入到设置表中。

设置将根据我部署的数据库而有所不同。

我如何脚本? Basicaly我想能够说两个文件,

Prod.Setting.sql和Dev.Setting.sql和VS 2010将使用适当的脚本,取决于什么

解决方案

完全可行,但有两个选项和几个步骤。您可以有一组完整的重复的脚本,每个配置一个。或者,您可以有一组脚本,其内容考虑您正在使用的配置。我会用第一个,我会保持简单。

创建两个解决方案配置,或者如果你喜欢使用Debug和Release。我将使用这些例子。

对于每个配置,创建一个新的.sqlcmdvars文件。

Database_Release.sqlcmdvars Database_Debug.sqlcmdvars

解决方案配置到每个和在数据库项目属性中更改变量文件下拉到指向您创建的相应文件。

在每个文件中,您可以定义变量在部署期间使用。在每个中创建一个新变量

$(DeploymentConfiguration)

并将其中每一个的值设置为Debug或Release

然后在任何Pre或Post部署脚本,您可以这样做:

IF'$(DeploymentConfiguration)'='Debug' BEGIN PRINT'执行调试部署':r .\Debug\SomeNeededScript.sql END 如果'$(DeploymentConfiguration)'='发布' BEGIN PRINT'执行发布部署':r .\Release\Anotherscript.sql END

I've got a Database project which works fine for my local MSSQL 2008 database.

It has a script under scripts/post-deployment that inserts standing data configuration into a settings table, and other tables. I've got 1 file for each table, e.g. a Setting.sql file to insert data into the Settings table.

The settings will be different depending on the database I deploy to.

How can I script this? Basicaly I would like to be able to have say 2 files,

Prod.Setting.sql and Dev.Setting.sql and VS 2010 would use the appropriate script depending on what database (environment) I am deploying to.

解决方案

Completely doable but there two options and a few steps involved. You can have a complete duplicate set of scripts, one for each configuration. Or, you can have one set of scripts, the contents of which take into account the configuration you are using. I'll go with the first, and I'll keep it simple.

Create two solution configurations, or use Debug and Release if you like. I'll use these for the example.

For each configuration, create a new .sqlcmdvars file.

Database_Release.sqlcmdvars Database_Debug.sqlcmdvars

Switch your solution configuration to each and in the database project properties change the variables file drop down to point at the corresponding file you created.

In each of those files you can define variables to be used during deployment. Create a new variable in each one

$(DeploymentConfiguration)

And set its value in each one to either Debug or Release

Then in any of your Pre or Post deployment scripts you can do something like so:

IF '$(DeploymentConfiguration)' = 'Debug' BEGIN PRINT 'Executing Debug deployment' :r .\Debug\SomeNeededScript.sql END IF '$(DeploymentConfiguration)' = 'Release' BEGIN PRINT 'Executing Release deployment' :r .\Release\Anotherscript.sql END

更多推荐

Visual Studio 2010数据库项目部署到不同的环境

本文发布于:2023-11-28 03:35:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   数据库   项目   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!